Block chain state snapshot generation method and device, computer equipment and storage medium

By obtaining the node set and state variables of the initial block and related blocks of the blockchain, a state snapshot of the target block is generated, which solves the problem of high resource consumption in the existing technology and achieves more efficient state snapshot generation.

CN119003451APending Publication Date: 2024-11-22HANGZHOU HIGH-TECH ZONE (BINJIANG) INSTITUTE OF BLOCKCHAIN & DATA SECURITY
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
CN202410922028.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-09
Publication Date
2024-11-22

AI Technical Summary

Technical Problem

Existing blockchain systems require traversing the entire state tree when generating state snapshots, resulting in significant consumption of computer resources and slow generation speed.

Method used

By obtaining the node set of the initial block and the block state variables of the associated blocks, the node set of the target block is determined, and a state snapshot is generated without traversing the entire state tree.

Benefits of technology

It effectively reduces computer resource consumption and improves the efficiency of state snapshot generation.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119003451A_ABST
    Figure CN119003451A_ABST
Patent Text Reader

Abstract

The invention relates to a block chain state snapshot generation method and device, computer equipment and a storage medium. The method comprises the following steps: acquiring a first node set of an initial block and a block state variable of an associated block, wherein the associated block comprises blocks associated with the initial block and a target block; the block state variable comprises node change information of a current block relative to a previous block; and based on the first node set and the block state variable of each associated block, determining a second node set of the target block, and taking the second node set as a state snapshot of the target block. According to the method, after the node set of the initial block and the block state variable of the associated block are obtained, the state snapshot of the target block can be calculated and determined, the state snapshot of the target block is determined under the condition that a full-amount state tree does not need to be traversed, computer resource consumption is effectively reduced, and the generation efficiency of the state snapshot is also improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of blockchain technology, and in particular to a method, device, computer equipment and storage medium for generating a blockchain state snapshot. Background Art

[0002] At present, common blockchain systems all use the state tree as a data structure to store the historical state of accounts and contracts. For example, the MPT tree (Merkle Patricia Tree) used by Ethereum and the JMT tree (Jellyfish Merkle Tree, a sparse Merkle tree) used by Aptos. State snapshots are generally generated on archive nodes (also called data nodes in some blockchain systems). Generating state snapshots can be abstracted as a process of traversing all nodes of the state tree under a specific block.

[0003] However, in traditional technology, since most of the nodes of the state tree exist on the disk, when generating a state snapshot in traditional technology, it is necessary to traverse and access each state tree node through level-order traversal, post-order traversal, etc., which means a large number of disk read and write operations, which requires more computer resources. Summary of the invention

[0004] Based on this, it is necessary to provide a blockchain state snapshot generation method, device, computer equipment and storage medium that can reduce computer resource consumption in response to the above technical problems.

[0005] In a first aspect, the present application provides a method for generating a blockchain state snapshot. The method comprises:

[0006] Acquire a first node set of an initial block and a block state variable of an associated block, wherein the associated block includes a block associated with the initial block and the target block; the block state variable includes node change information of the current block compared with the previous block;

[0007] Based on the first node set and the block state variables of each of the associated blocks, a second node set of the target block is determined, and the second node set is used as a state snapshot of the target block.

[0008] In one embodiment, the block state variable includes a block state increment and a block state decrement, wherein the block state increment includes a set of incremented nodes of the current block compared to the previous block, and the block state decrement includes a set of decremented nodes of the current block compared to the previous block.

[0009] In one embodiment, if the block height of the initial block is greater than the block height of the target block, the associated block includes the intermediate block between the initial block and the target block and the initial block;

[0010] If the block height of the initial block is smaller than the block height of the target block, the associated blocks include the intermediate block between the initial block and the target block and the target block.

[0011] In one embodiment, if the block height of the initial block is greater than the block height of the target block, determining the second node set of the target block based on the first node set and the block state variables of each associated block includes:

[0012] Determine a node set of a previous block based on the node set of the initial block and the block state variable of the initial block;

[0013] Based on the node set of the previous block and the block state variables of the intermediate block, the node set of each intermediate block is determined in sequence until the second node set of the target block is determined.

[0014] In one embodiment, determining the node set of the previous block based on the node set of the initial block and the block state variable of the initial block includes:

[0015] In the node set of the initial block, the node corresponding to the block state increment of the initial block is deleted, and the node corresponding to the block state decrement of the initial block is inserted to obtain the node set of the previous block.

[0016] In one embodiment, if the block height of the initial block is less than the block height of the target block, determining the node set of the target block based on the first node set and the block state variables of each associated block includes:

[0017] Determine a node set of a subsequent block based on the node set of the initial block and a block state variable of a block subsequent to the initial block;

[0018] Based on the node set of the subsequent block and the block state variables of the intermediate block, the node set of each intermediate block is determined in sequence until the second node set of the target block is determined.

[0019] In one embodiment, determining the node set of the subsequent block based on the node set of the initial block and the block state variable of the subsequent block of the initial block includes:

[0020] The node set of the subsequent block is obtained by inserting the node corresponding to the block state increment of the subsequent block into the node set of the initial block and deleting the node corresponding to the block state decrement of the subsequent block.

[0021] In one embodiment, determining the second node set of the target block based on the first node set and the block state variable of each associated block further includes:

[0022] Determining a total block state variable based on the block state variable of each of the associated blocks;

[0023] Based on the first node set and the total block state variable, determine the node set of the target block.

[0024] In one embodiment, the total block state variable includes a total block state increment and a total block state decrement; and determining the total state variable based on the block state variable of each associated block includes:

[0025] Determining a total block state decrement based on the block state decrement of each of the associated blocks;

[0026] Based on the block state increment of each of the associated blocks, a total block state increment is determined.

[0027] In one embodiment, determining the node set of the target block based on the node set of the initial block and the total state variable includes:

[0028] If the block height of the initial block is greater than the block height of the target block, then in the node set of the initial block, the node corresponding to the total block state increment is deleted, and the node corresponding to the total block state decrement is inserted to obtain the node set of the target block;

[0029] If the block height of the initial block is less than the block height of the target block, the node set of the target block is obtained by inserting the node corresponding to the increment of the total block state and deleting the node corresponding to the decrement of the total block state in the node set of the initial block.

[0030] In a second aspect, the present application also provides a blockchain state snapshot generation device. The device comprises:

[0031] A data acquisition module, used to acquire a first node set of an initial block and block state variables of associated blocks, wherein the associated blocks include blocks associated with the initial block and the target block; the block state variables include node change information of a current block compared with a previous block;

[0032] A state snapshot generation module is used to determine a second node set of the target block based on the first node set and the block state variables of each of the associated blocks, and use the second node set as the state snapshot of the target block.

[0033] In a third aspect, the present application further provides a computer device. The computer device includes a memory and a processor, the memory stores a computer program, and the processor implements the steps of any blockchain state snapshot generation method in the first aspect when executing the computer program.

[0034] In a fourth aspect, the present application further provides a computer-readable storage medium, wherein a computer program is stored thereon, and when the computer program is executed by a processor, the steps of any one of the blockchain state snapshot generation methods in the first aspect are implemented.

[0035] The above-mentioned blockchain state snapshot generation method, device, computer equipment and storage medium obtain the first node set of the initial block and the block state variables of the associated blocks, the associated blocks include blocks associated with the initial block and the target block; the block state variables include node change information of the current block compared to the previous block; then based on the first node set and the block state variables of each associated block, the second node set of the target block is determined, and the second node set is used as the state snapshot of the target block. After obtaining the node set of the initial block and the block state variables of the associated blocks, the state snapshot of the target block can be calculated and determined, and the state snapshot of the target block can be determined without traversing the full state tree, which effectively reduces the consumption of computer resources and improves the efficiency of generating state snapshots.

[0036] Details of one or more embodiments of the present application are set forth in the following drawings and description to make other features, objects, and advantages of the present application more readily apparent. BRIEF DESCRIPTION OF THE DRAWINGS

[0037] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:

[0038] Figure 1 This is an application environment diagram of a blockchain state snapshot generation method in one embodiment;

[0039] Figure 2 It is a flowchart of a method for generating a blockchain state snapshot in one embodiment;

[0040] Figure 3 It is a schematic diagram of a method for generating a block status snapshot in a specific embodiment;

[0041] Figure 4 It is a structural block diagram of a blockchain state snapshot generating device in one embodiment;

[0042] Figure 5 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION

[0043] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.

[0044] Unless otherwise defined, the technical terms or scientific terms involved in this application shall have the general meaning understood by people with ordinary skills in the technical field to which this application belongs. The words "one", "a", "a", "the", "these" and the like in this application do not represent quantitative restrictions, and they can be singular or plural. The terms "include", "comprise", "have" and any variants thereof involved in this application are intended to cover non-exclusive inclusions; for example, a process, method and system, product or device comprising a series of steps or modules (units) is not limited to the listed steps or modules (units), but may include unlisted steps or modules (units), or may include other steps or modules (units) inherent to these processes, methods, products or devices. The words "connect", "connected", "coupled" and the like involved in this application are not limited to physical or mechanical connections, but may include electrical connections, whether directly or indirectly. The "multiple" involved in this application refers to two or more. "And / or" describes the association relationship of associated objects, indicating that there can be three relationships. For example, "A and / or B" can mean: A exists alone, A and B exist at the same time, and B exists alone. Usually, the character " / " indicates that the objects associated with each other are in an "or" relationship. The terms "first", "second", "third", etc. involved in this application are only used to distinguish similar objects and do not represent a specific ordering of the objects.

[0045] The terms "module", "unit", etc. used below are a combination of software and / or hardware that can implement a predetermined function. Although the devices described in the following embodiments are preferably implemented in hardware, the implementation of software, or a combination of software and hardware is also possible and conceivable.

[0046] In traditional technologies, the method of generating a blockchain state snapshot is based on traversing the entire state tree. However, as the blockchain ledger data continues to expand, this process consumes more and more computer resources and the generation speed becomes slower and slower. Currently, common blockchain systems all use the state tree as the data structure for storing the historical states of accounts and contracts. For example, the MPT tree used by Ethereum and the JMT tree used by Aptos, etc.

[0047] A state snapshot refers to the full world state of the blockchain at a certain block, which can be considered as the full data of the world state tree corresponding to that block. State snapshots are mainly used for the rapid joining of new nodes. Suppose the block height of the current blockchain network is Y. When a new node wants to join the blockchain network, it only needs to determine the state snapshot at block height X (X < Y), and then it can quickly synchronize to the latest state of the network by only replaying the blocks between X and Y. Without a state snapshot, when a new node joins the network, it must replay all the blocks before Y. As Y increases, the resources consumed by this process also continuously increase, resulting in an increasingly high threshold for new nodes to participate in the network.

[0048] State snapshots are generally generated on archival nodes (also called data nodes in some blockchain systems). Taking Ethereum as an example, the archival nodes of Ethereum hold the full historical state, so they can generate state snapshots for any block. Generating a state snapshot can be abstracted as a process of traversing all the nodes of the state tree under a specific block. Taking the account state tree as an example, when there are N accounts, the total number of nodes in the state tree is O(NlogN) on average. Considering that the state of the blockchain is constantly expanding, the number of N is also continuously increasing. And traversing the state tree once requires accessing O(NlogN) state tree nodes. Since most of the nodes of the state tree are stored on disk, this means a large number of disk read and write operations, which consume a large amount of computer resources. For example, if the block height of the current latest block is 10 and it is necessary to determine the state snapshot at block height 5, in traditional technologies, it is necessary to determine the root node field included in the block header of block 5, that is, the root node of the state tree of block 5. Then, based on this root node, traverse this state tree in the ledger (such as strategies like level-order traversal, post-order traversal, etc.) and read each node of the state tree, which consumes a lot of computer resources.

[0049] On the other hand, the snapshot generation method based on traversing the state tree has other limitations, namely, it is difficult for a full node that only retains the latest state to generate a state snapshot of the previous block. A full node refers to a node that only retains the historical state of the last few blocks. Normally, a full node will only retain the latest block history through state pruning, so that it can still participate in consensus and execution normally while saving storage space to the maximum extent. However, due to the loss of the historical state before the current block, it is difficult for a full node to support the generation of a state snapshot of any block height like an archive node.

[0050] Based on this, the present application provides a blockchain state snapshot generation method. The blockchain state snapshot generation method provided in the present application embodiment can be applied to Figure 1 In the application environment shown. Among them, the terminal 102 communicates with the server 104 through the network. The data storage system can store the data that the server 104 needs to process. The data storage system can be integrated on the server 104, or it can be placed on the cloud or other network servers. The terminal 102 obtains the first node set of the initial block and the block state variables of the associated block and sends them to the server 104, wherein the associated block includes a block associated with the initial block and the target block; the block state variable includes the node change information of the current block compared to the previous block. The server 104 determines the second node set of the target block based on the first node set and the block state variables of each of the associated blocks, and sends the second node set as the state snapshot of the target block to the terminal 102. In other embodiments, the above steps can also be performed only by the terminal 102 or the server 104, and this application does not make specific restrictions on this. Among them, the terminal 102 can be, but is not limited to, various personal computers, laptops, smart phones, tablet computers, etc. The server 104 can be implemented with an independent server or a server cluster consisting of multiple servers.

[0051] In an embodiment of the present application, a method for generating a blockchain state snapshot is provided, the method comprising:

[0052] S201: Acquire a first node set of an initial block and block state variables of associated blocks, wherein the associated blocks include blocks associated with the initial block and the target block; the block state variables include node change information of a current block compared to a previous block.

[0053] In the embodiment of the present application, a block is the smallest component unit of a blockchain, an initial block includes a block corresponding to the starting position for generating a blockchain state snapshot, and a target block includes a block for generating a state snapshot. In some embodiments, the initial block can be considered to be the starting block for generating a state snapshot, and the target block is the end block for generating the state snapshot. Specifically, the initial block can include any block in the blockchain, and the target block can also include any block in the blockchain, but the initial block and the target block are not the same block. That is, by the blockchain state snapshot generation method provided in the embodiment of the present application, it is possible to determine the state snapshot of any block other than the block starting from any block in the blockchain.

[0054] It should be noted that the nodes in the node set described in this application include nodes of the blockchain state tree data structure, not blockchain nodes. The nodes of the state tree data structure include intermediate nodes and leaf nodes in the blockchain state tree data structure, and the blockchain nodes include computers or devices participating in the blockchain network, which maintain and manage the operation of the blockchain by running the blockchain protocol. In addition, a blockchain full node is a type of blockchain node. The full node has the full state tree data of the latest block of the blockchain, can independently verify transactions and participate in the consensus mechanism. The state change information generated by the execution of the block by the blockchain full node will be applied to the blockchain state tree, which may add a node set of the state tree data structure, that is, the block state increment, and / or delete the node set of the state tree data structure, that is, the block state decrement.

[0055] In an embodiment of the present application, the associated blocks include blocks associated with the initial block and the target block. In some embodiments, if the block height of the initial block is greater than the block height of the target block, the associated blocks include the intermediate block between the initial block and the target block and the initial block; if the block height of the initial block is less than the block height of the target block, the associated blocks include the intermediate block between the initial block and the target block and the target block.

[0056] In some specific embodiments, if the block height of the initial block in a blockchain is 30 and the block height of the target block is 13, the associated blocks include the intermediate blocks between the initial block and the target block and the initial block, that is, the associated blocks include intermediate blocks 14 to 29, and initial block 30. In another specific embodiment, if the block height of the initial block in a blockchain is 15 and the block height of the target block is 26, the associated blocks include intermediate blocks 16 to 25, and target block 26. In the embodiments of the present application, N in "block N" represents the block height, which will not be repeated in the following text.

[0057] One of the core tasks of blockchain runtime is to continuously execute transactions in new blocks, apply the transaction execution results to the world state of the current ledger, and obtain a new world state. Therefore, the state variables generated by the nodes based on each block can be recorded based on the block dimension.

[0058] In an embodiment of the present application, the block state variable includes the node change information of the current block compared to the previous block. That is, the block state variable includes the node change information of the latter block relative to the previous block in two adjacent blocks. Among them, the current block may include any block in the associated block. The "front" or "back" in the blockchain described in the embodiment of the present application is based on the direction of the blockchain structure, that is, the direction "back" includes the direction from the genesis block to the latest block, and the "front" includes the direction from the latest block to the genesis block, and the genesis block is the earliest constructed block in the blockchain, that is, the block with a block height of 0. In some specific embodiments, if blocks 3-6 are intermediate blocks, the block state variable of block 4 includes the node change information of block 4 compared to block 3.

[0059] In some embodiments, the block state variable includes a block state increment and a block state decrement, wherein the block state increment includes an increment node set of the current block compared to the previous block, and the block state decrement includes a decrement node set of the current block compared to the previous block. It can be understood that if the current block has no newly added nodes or no deleted nodes compared to the previous block, the corresponding increment node set or decrement node set is an empty set.

[0060] In some specific embodiments, if blocks 5 and 6 are both intermediate blocks, and the node set of block 5 is A, B, C, D, and the node set of block 6 is C, D, E, F. Then block 5 is the previous block of block 6, the block state increment of block 6 is the node set including nodes E and F, and the block state decrement of block 6 is the node set including nodes A and B.

[0061] S203: Determine a second node set of the target block based on the first node set and the block state variable of each of the associated blocks, and use the second node set as a state snapshot of the target block.

[0062] In the embodiment of the present application, the second node set of the target block may include the world state of all nodes when the target block is the latest block. After determining the first node set of the initial block and the block state variables of each associated block, the second node set of the target block may be determined. The second node set is then used as the state snapshot of the target block.

[0063] Specifically, in some embodiments, the node set of each intermediate block can be determined in sequence starting from the initial block according to the first node set and the block state variables of each associated block, until the second node set of the target block is finally determined. In other embodiments, the total block state variable of the target block compared to the initial block can be determined according to the block state variables of the associated blocks, and then the second node set of the target block can be determined according to the first node set of the initial block and the total block state variables.

[0064] The blockchain state snapshot generation method provided in the embodiment of the present application obtains the first node set of the initial block and the block state variables of the associated blocks, the associated blocks include blocks associated with the initial block and the target block; the block state variables include node change information of the current block compared to the previous block; then based on the first node set and the block state variables of each associated block, the second node set of the target block is determined, and the second node set is used as the state snapshot of the target block. After obtaining the node set of the initial block and the block state variables of the associated blocks, the state snapshot of the target block can be calculated and determined, and the state snapshot of the target block can be determined without traversing the full state tree, which effectively reduces the consumption of computer resources and improves the efficiency of generating state snapshots.

[0065] The following is an explanation of an implementation method of generating a state snapshot of a target block when the block height of the initial block is greater than the block height of the target block through an embodiment of the present application.

[0066] In some embodiments, if the block height of the initial block is greater than the block height of the target block, determining the second node set of the target block based on the first node set and the block state variables of each associated block includes:

[0067] S301: Determine the node set of the previous block based on the node set of the initial block and the block state variable of the initial block.

[0068] S303: Based on the node set of the previous block and the block state variables of the intermediate block, determine the node set of each intermediate block in turn until the second node set of the target block is determined.

[0069] In an embodiment of the present application, the block state variable of the initial block includes the node change information of the initial block compared to the previous block, so based on the node set of the initial block and the block state variable of the initial block, the node set of the previous block can be determined. The intermediate block includes the previous block. Similarly, if the previous block is used as the current block, then based on the node set of the current block and the block state variable of the previous block of the current block, the node set of each intermediate block can be determined in turn. After determining the node set of the block after the target block, based on the node set of the block after the target block and the block state variable, the second node set of the target block can be finally determined.

[0070] In some embodiments, determining the node set of the previous block based on the node set of the initial block and the block state variable of the initial block includes:

[0071] S401: In the node set of the initial block, the node corresponding to the block state increment of the initial block is deleted, and the node corresponding to the block state decrement of the initial block is inserted, so as to obtain the node set of the previous block.

[0072] Similar to step S401, the node set of each intermediate block is determined in turn based on the node set of the previous block and the block state variable of the intermediate block in the above step S303 until the second node set of the target block is determined. It can also include deleting the node corresponding to the block state increment of the previous block in the node set of the previous block, and inserting the node corresponding to the block state decrement of the previous block, and repeating the above steps until the second node set of the target block is determined.

[0073] It should be noted that each node in the state tree is stored in the form of Key-Value on the disk. For example, the form of node N stored on the disk is "node N identifier → node N data". If you need to add a new node N, you can write a piece of data "insert, node N identifier, node N data"; to delete node N, you can write a piece of data "delete, node 8 identifier". The above process of adding and deleting node N does not require the information of the node's layer number. Based on the design of the state tree, once the identifier of each node is generated, the position of the node in the state tree is uniquely determined, and the identifier can be inferred and constructed from its parent node information.

[0074] The blockchain state snapshot generation method provided by this application can be divided into the following two cases according to different execution objects of specific steps: determining the state snapshot of the target block without changing the current blockchain state, and rolling back the current blockchain state. The implementation manners in the above two cases are respectively described below through two specific embodiments.

[0075] In some specific embodiments, if it is necessary to determine the state snapshot of the target block without changing the current blockchain state. Assume that the initial block height of the current full node is Y, and only the world state of the initial block Y is retained, that is, the first node set of the initial block Y is retained. Obtain the block state variables of each block from block X (X < Y) to block Y. Define the block state increment as the write set (WriteSet), and the write set (WriteSet) includes the incremental node set of the current block compared with the previous block; define the block state decrement as the prune set (PruneSet), and the prune set (PruneSet) includes the decremental node set of the current block compared with the previous block.

[0076] If it is necessary to generate the state snapshot of the target block N (N ≥ X and N < Y), it can be achieved by performing the following steps:

[0077] S501: Let i be equal to Y. In order not to affect the original ledger of the full node, that is, not to affect the world state of the current blockchain, copy the current world state to the directory Dir, and all subsequent operations are based on the directory Dir.

[0078] S503: Determine whether i is equal to N. If so, the snapshot generation ends, and the data in the directory Dir is the state snapshot of the target block N; if not, execute steps S505 and S507.

[0079] S505: Operate on the state variables of block i. Specifically, first, obtain the block state increment write set (WriteSet) of block i, and delete the state tree nodes included in the write set (WriteSet) on the ledger in the directory Dir; then, obtain the block state decrement prune set (PruneSet) of block i, and insert the state tree nodes included in the prune set (PruneSet) on the ledger in the directory Dir.

[0080] S507: Let i = i - 1, and execute step S503.

[0081] The implementation manner of step S505 is further described below through a specific embodiment, such as Figure 3As shown in the figure, the full-node world state of the current block BlockX+1 is represented within the red dashed box, that is, the current block height is X+1, and its node set is {8, 3, 9, 6, 7, 10, 11}. The block state variables of the current block X+1 are represented within the blue dashed box, that is, for the current block X+1 relative to the previous block X, four nodes {1, 2, 4, 5} are pruned, and four nodes {8, 9, 10, 11} are newly added. If you want to generate a state snapshot of block X, you can delete the block state incremental write set (WriteSet) {8, 9, 10, 11} from the ledger of block X+1, and then re-add the block state decremental pruning set (PruneSet) {1, 2, 4, 5}, and the state snapshot at block X can be obtained as the node set {1, 2, 3, 4, 5, 6, 7}.

[0082] In some other specific embodiments, assume that the block height of the current full node is Y, that is, the latest block is block Y, and only the world state of block Y is retained, and the block state variables of each block from block X (X < Y) to block Y are held. If you want to roll back to the target block N (N ≥ X and N < Y).

[0083] If it is necessary to roll back the world state of the current blockchain, it can be achieved by performing the following steps:

[0084] S601: Let i be equal to Y, and the subsequent steps directly operate on the original ledger.

[0085] S603: Determine whether i is equal to N. If so, the snapshot generation ends, the rollback operation is completed, and the full node is restarted; if not, execute steps S605 and S607.

[0086] S605: Operate on the state variables of block i. Specifically, first, obtain the block state incremental write set (WriteSet) of block i, and delete the state tree nodes included in the write set (WriteSet) on the original ledger; then, obtain the block state decremental pruning set (PruneSet) of block i, and insert the state tree nodes included in the pruning set (PruneSet) on the original ledger.

[0087] S607: Let i = i - 1, and execute step S603.

[0088] The following is illustrated by the embodiments of the present application. When the block height of the initial block is less than the block height of the target block, the implementation manner of generating the state snapshot of the target block is described.

[0089] In some embodiments, if the block height of the initial block is less than the block height of the target block, the determining the node set of the target block based on the first node set and the block state variables of each associated block includes:

[0090] S701: Determine a node set of a subsequent block based on the node set of the initial block and a block state variable of a subsequent block of the initial block.

[0091] S703: Based on the node set of the next block and the block state variable of the intermediate block, determine the node set of each intermediate block in turn until the second node set of the target block is determined.

[0092] In an embodiment of the present application, the block state variable of the block after the initial block includes the node change information of the latter block compared to the initial block, so based on the node set of the initial block and the block state variable of the latter block, the node set of the block after the initial block can be determined. The intermediate block includes the latter block. Similarly, if the latter block is used as the current block, then based on the node set of the current block and the block state variable of the block after the current block, the node set of each intermediate block can be determined in turn. After determining the node set of the previous block of the target block, based on the node set of the previous block of the target block and the block state variable of the target block, the second node set of the target block can be finally determined.

[0093] In some embodiments, the determining the node set of the subsequent block based on the node set of the initial block and the block state variable of the subsequent block of the initial block includes:

[0094] S801: In the node set of the initial block, a node corresponding to the block state increment of the subsequent block is inserted, and a node corresponding to the block state decrement of the subsequent block is deleted, to obtain the node set of the subsequent block.

[0095] Similar to step S701, the node set of each intermediate block is determined in turn based on the node set of the subsequent block and the block state variable of the intermediate block in the above step S703 until the second node set of the target block is determined. It can also include inserting a node corresponding to the block state increment of the subsequent block of the current block into the node set of the current block, and deleting a node corresponding to the block state decrement of the subsequent block, and repeating the above steps until the second node set of the target block is determined.

[0096] Another implementation method for determining the second node set of the target block is described below through an embodiment of the present application.

[0097] In some embodiments, determining the second node set of the target block based on the first node set and the block state variables of each associated block further comprises:

[0098] S901: Determine a total block state variable based on the block state variable of each associated block.

[0099] S903: Determine the node set of the target block based on the first node set and the total block state variable.

[0100] In an embodiment of the present application, based on the block state variable of each associated block, determining the total block state variable may include taking the union of the block state increments of all associated blocks and the union of the block state decrements of all associated blocks as the total block state variable. In other embodiments, the associated blocks may be divided into multiple block sets, and the union of the block state increments and the union of the block state decrements of each block set are determined respectively, and then the total block state variable is determined. The present application does not specifically limit the method for determining the total block state variable.

[0101] In the embodiment of the present application, after determining the first node set of the initial block and the total block state variable of the current block compared to the initial block, the node set of the target block can be determined.

[0102] In some embodiments, the total block state variable includes a total block state increment and a total block state decrement; and determining the total state variable based on the block state variable of each associated block includes:

[0103] S1001: Determine a total block state decrement based on the block state decrement of each associated block.

[0104] S1003: Determine a total block state increment based on the block state increment of each associated block.

[0105] In the embodiment of the present application, the block state decrements of each associated block can be taken as the union, that is, the decrement node set corresponding to all associated blocks, as the total block state decrement. And the block state increments of each associated block can be taken as the union, that is, the increment node set corresponding to all associated blocks, as the total block state increment.

[0106] In some embodiments, determining the node set of the target block based on the node set of the initial block and the total state variable includes:

[0107] S1101: If the block height of the initial block is greater than the block height of the target block, in the node set of the initial block, the node corresponding to the total block state increment is deleted, and the node corresponding to the total block state decrement is inserted to obtain the node set of the target block;

[0108] S1103: If the block height of the initial block is less than the block height of the target block, then in the node set of the initial block, a node corresponding to the increment of the total block state is inserted, and a node corresponding to the decrement of the total block state is deleted to obtain the node set of the target block.

[0109] In the embodiment of the present application, based on the node set of the initial block and the total state variable, the node set of the target block is determined in two ways, namely, the block height of the initial block is greater than the block height of the target block, or the block height of the initial block is less than the block height of the target block. Further, there are multiple ways to determine the total block state variable, and the following is an explanation of the way to determine the total block state variable.

[0110] In some embodiments, the block state decrements of each associated block can be directly taken as the union, that is, the set of decrement nodes corresponding to all associated blocks, as the total block state decrement. And the block state increments of each associated block can be taken as the union, that is, the set of increment nodes corresponding to all associated blocks, as the total block state increment. For example, if there are two associated blocks A and B, the block state increment of block A is {2, 3, 4}, and the block state decrement is {5, 6}; the block state increment of block B is {5, 7}, and the block state decrement is {8}. Then the total block state increment is {2, 3, 4, 5, 7}, and the total block state decrement is {5, 6, 8}. Correspondingly, if the block height of the initial block is greater than the block height of the target block, the node set of the target block is obtained by deleting the nodes {2, 3, 4, 5, 7} corresponding to the total block state increment and inserting the nodes {5, 6, 8} corresponding to the total block state decrement in the node set of the initial block. At this time, for node 5, the steps of first deleting and then inserting are actually performed.

[0111] In other embodiments, the total block state variable after offset can also be calculated, and then the node set of the target block is determined. Still taking the above embodiment as an example, the total block state increment is {2, 3, 4, 5, 7}, and the total block state decrement is {5, 6, 8}. At this time, node 5 exists in both the total block state increment and the total block state decrement, and node 5 can be offset. The total block state increment after offset is {2, 3, 4, 7}, and the total block state decrement is {6, 8}. Correspondingly, in the node set of the initial block, the node {2, 3, 4, 7} corresponding to the total block state increment is deleted, and the node {6, 8} corresponding to the total block state decrement is inserted to obtain the node set of the target block. At this time, for node 5, the offset operation has been performed in the process of determining the total block state variable, so in the process of determining the node set of the target block based on the node set of the initial block and the total state variable, there is no need to perform the steps of first deleting and then inserting.

[0112] The blockchain state snapshot generation method provided in this application can be applied to the JMT tree used by blockchains such as Aptos. In the same JMT tree, there will not be multiple paths sharing a leaf node on the physical disk. Therefore, after operating the current block, the dereferenced nodes can be recorded in the pruned set, and the newly added nodes can be recorded in the write set at the same time.

[0113] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.

[0114] Based on the same inventive concept, the embodiment of the present application also provides a blockchain state snapshot generation device for implementing the blockchain state snapshot generation method involved above. The implementation scheme for solving the problem provided by the device is similar to the implementation scheme recorded in the above method, so the specific limitations in the one or more blockchain state snapshot generation device embodiments provided below can refer to the limitations of the blockchain state snapshot generation method above, and will not be repeated here.

[0115] In one embodiment, Figure 4 As shown, a blockchain state snapshot generation device 1200 is provided, comprising:

[0116] The data acquisition module 1201 is used to acquire the first node set of the initial block and the block state variables of the associated blocks, wherein the associated blocks include blocks associated with the initial block and the target block; the block state variables include node change information of the current block compared with the previous block;

[0117] The state snapshot generation module 1202 is used to determine a second node set of the target block based on the first node set and the block state variables of each of the associated blocks, and use the second node set as the state snapshot of the target block.

[0118] In one embodiment, the block state variable includes a block state increment and a block state decrement, wherein the block state increment includes a set of increment nodes of the current block compared to the previous block, and the block state decrement includes a set of decrement nodes of the current block compared to the previous block.

[0119] In one embodiment, if the block height of the initial block is greater than the block height of the target block, the associated blocks include the intermediate block between the initial block and the target block and the initial block; if the block height of the initial block is less than the block height of the target block, the associated blocks include the intermediate block between the initial block and the target block and the target block.

[0120] In one embodiment, if the block height of the initial block is greater than the block height of the target block, the state snapshot generation module 1202 is further used to determine the node set of the previous block based on the node set of the initial block and the block state variable of the initial block; based on the node set of the previous block and the block state variable of the intermediate block, determine the node set of each intermediate block in turn until the second node set of the target block is determined.

[0121] In one embodiment, the state snapshot generation module 1202 is further used to obtain the node set of the previous block by deleting the node corresponding to the block state increment of the initial block and inserting the node corresponding to the block state decrement of the initial block in the node set of the initial block.

[0122] In one embodiment, if the block height of the initial block is less than the block height of the target block, the state snapshot generation module 1202 is further used to determine the node set of the subsequent block based on the node set of the initial block and the block state variables of the subsequent block of the initial block; based on the node set of the subsequent block and the block state variables of the intermediate blocks, determine the node set of each of the intermediate blocks in turn until the second node set of the target block is determined.

[0123] In one embodiment, the state snapshot generation module 1202 is further used to insert the node corresponding to the block state increment of the subsequent block into the node set of the initial block, and delete the node corresponding to the block state decrement of the subsequent block, so as to obtain the node set of the subsequent block.

[0124] In one embodiment, the state snapshot generation module 1202 is further used to determine the total block state variable based on the block state variable of each of the associated blocks; and determine the node set of the target block based on the first node set and the total block state variable.

[0125] In one embodiment, the state snapshot generation module 1202 is further used to determine the total block state decrement based on the block state decrement of each of the associated blocks; and determine the total block state increment based on the block state increment of each of the associated blocks.

[0126] In one embodiment, the state snapshot generation module 1202 is further used for, if the block height of the initial block is greater than the block height of the target block, deleting the node corresponding to the total block state increment in the node set of the initial block, and inserting the node corresponding to the total block state decrement to obtain the node set of the target block; if the block height of the initial block is less than the block height of the target block, inserting the node corresponding to the total block state increment in the node set of the initial block, and deleting the node corresponding to the total block state decrement to obtain the node set of the target block.

[0127] Each module in the above-mentioned blockchain state snapshot generation device 1200 can be implemented in whole or in part by software, hardware, or a combination thereof. Each of the above-mentioned modules can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each of the above modules.

[0128] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Figure 5 As shown. The computer device includes a processor, a memory and a network interface connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store data. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a blockchain state snapshot generation method is implemented.

[0129] Those skilled in the art will understand that Figure 5 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.

[0130] In one embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and when the processor executes the computer program, the steps of the method for generating a blockchain state snapshot described in any of the above embodiments are implemented.

[0131] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps of the blockchain state snapshot generation method described in any of the above embodiments are implemented.

[0132] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties.

[0133] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.

[0134] The technical features of the above embodiments may be arbitrarily combined. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

[0135] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.

Claims

1. A method for generating a blockchain state snapshot, characterized in that: The method comprises: Acquire a first node set of an initial block and a block state variable of an associated block, wherein the associated block includes a block associated with the initial block and the target block; the block state variable includes node change information of the current block compared with the previous block; Based on the first node set and the block state variables of each of the associated blocks, a second node set of the target block is determined, and the second node set is used as a state snapshot of the target block.

2. The method according to claim 1, characterized in that The block state variable includes a block state increment and a block state decrement, wherein the block state increment includes an increment node set of the current block compared to the previous block, and the block state decrement includes a decrement node set of the current block compared to the previous block.

3. The method according to claim 2, characterized in that If the block height of the initial block is greater than the block height of the target block, the associated blocks include the intermediate block between the initial block and the target block and the initial block; If the block height of the initial block is smaller than the block height of the target block, the associated blocks include the intermediate block between the initial block and the target block and the target block.

4. The method according to claim 3, characterized in that If the block height of the initial block is greater than the block height of the target block, determining the second node set of the target block based on the first node set and the block state variables of each associated block includes: Determine a node set of a previous block based on the node set of the initial block and the block state variable of the initial block; Based on the node set of the previous block and the block state variables of the intermediate block, the node set of each intermediate block is determined in sequence until the second node set of the target block is determined.

5. The method according to claim 4, characterized in that The determining the node set of the previous block based on the node set of the initial block and the block state variable of the initial block includes: In the node set of the initial block, the node corresponding to the block state increment of the initial block is deleted, and the node corresponding to the block state decrement of the initial block is inserted to obtain the node set of the previous block.

6. The method according to claim 3, characterized in that If the block height of the initial block is less than the block height of the target block, determining the node set of the target block based on the first node set and the block state variables of each associated block includes: Determine a node set of a subsequent block based on the node set of the initial block and a block state variable of a block subsequent to the initial block; Based on the node set of the subsequent block and the block state variables of the intermediate block, the node set of each intermediate block is determined in sequence until the second node set of the target block is determined.

7. The method according to claim 6, characterized in that The determining of the node set of the subsequent block based on the node set of the initial block and the block state variable of the subsequent block of the initial block comprises: The node set of the subsequent block is obtained by inserting the node corresponding to the block state increment of the subsequent block into the node set of the initial block and deleting the node corresponding to the block state decrement of the subsequent block.

8. The method according to claim 2, characterized in that: The determining the second node set of the target block based on the first node set and the block state variable of each associated block further comprises: Determining a total block state variable based on the block state variable of each of the associated blocks; Based on the first node set and the total block state variable, determine the node set of the target block.

9. The method according to claim 8, characterized in that The total block state variable includes a total block state increment and a total block state decrement; Determining the total state variable based on the block state variable of each associated block includes: Determining a total block state decrement based on the block state decrement of each of the associated blocks; Based on the block state increment of each of the associated blocks, a total block state increment is determined.

10. The method according to claim 9, characterized in that The step of determining the node set of the target block based on the node set of the initial block and the total state variable includes: If the block height of the initial block is greater than the block height of the target block, then in the node set of the initial block, the node corresponding to the total block state increment is deleted, and the node corresponding to the total block state decrement is inserted to obtain the node set of the target block; If the block height of the initial block is less than the block height of the target block, the node set of the target block is obtained by inserting the node corresponding to the increment of the total block state and deleting the node corresponding to the decrement of the total block state in the node set of the initial block.

11. A blockchain state snapshot generation device, characterized in that: The device comprises: A data acquisition module, used to acquire a first node set of an initial block and block state variables of associated blocks, wherein the associated blocks include blocks associated with the initial block and the target block; the block state variables include node change information of a current block compared with a previous block; A state snapshot generation module is used to determine a second node set of the target block based on the first node set and the block state variables of each of the associated blocks, and use the second node set as the state snapshot of the target block.

12. A computer device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 10 are implemented.

13. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 10 are implemented.

Citation Information

Patent Citations

  • Taking snapshots of blockchain data

    CA3098939A1

  • Block chain snapshot making method based on modification set

    CN110489495A

  • Data storage method and device based on block chain, equipment and readable storage medium

    CN113971002A

  • Data processing method, device and equipment based on block chain and readable storage medium

    CN116488818A

  • Data processing method, device and equipment based on block chain and readable storage medium

    CN117390117A