Blockchain-based state data reconstruction method and device, and storage medium

By retrieving blocks that affect state data from the blockchain, determining the starting block, and obtaining transaction data, the problem of low efficiency in blockchain state data reconstruction is solved, and efficient state data reconstruction is achieved.

CN115168444BActive Publication Date: 2026-03-17INDUSTRIAL AND COMMERCIAL BANK OF CHINA
View PDF 3 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-06-24
Publication Date
2026-03-17

AI Technical Summary

Technical Problem

In existing technologies, the large number of blocks required for blockchain state data reconstruction leads to low reconstruction efficiency.

Method used

By retrieving blocks from the blockchain that affect the state data, the starting block is determined, and transaction data is retrieved sequentially to reconstruct the state data. The synchronization mechanism between the master node and the slave node is used to improve the reconstruction efficiency.

Benefits of technology

It has achieved efficient reconstruction of state data, shortened reconstruction time, and improved reconstruction efficiency.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115168444B_ABST
    Figure CN115168444B_ABST
Patent Text Reader

Abstract

This application discloses a method, apparatus, and storage medium for reconstructing state data based on a blockchain. Relating to the blockchain field, the method includes: obtaining blocks from the blockchain that affect the state data of the blockchain, resulting in multiple first blocks; sequentially obtaining transaction data from the multiple first blocks, starting from the first block; and reconstructing the state data based on the obtained transaction data. This application solves the problem in related technologies where the reconstruction efficiency of state data is low due to the large number of blocks.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of blockchain, and more specifically, to a method, apparatus, and storage medium for reconstructing state data based on blockchain. Background Technology

[0002] In the field of blockchain technology, there are three scenarios where state data reconstruction is required: Scenario 1: A new organization joins the blockchain network, and state data reconstruction is required on the nodes of the new organization; Scenario 2: A new organization's slave nodes join the blockchain network or the organization expands, and state data reconstruction is required on the slave nodes; Scenario 3: After the master peer node fails and crashes, it recovers, and state data reconstruction is required on the master peer node.

[0003] The existing method for reconstructing blockchain state data is as follows: the client sends a state data reconstruction request, the server establishes a state data reconstruction task, and a long-lived connection is established between the client and the server. In the state data reconstruction task, the server starts from the first block in the blockchain and pushes blocks to the client in the order they were created. The client continuously receives blocks, verifies them, executes them sequentially, and submits the write sets from each block to its local state database, ultimately completing the state data reconstruction.

[0004] For scenarios one and two, which require state data reconstruction, newly added nodes need to synchronize all blocks in the blockchain to rebuild their state data. As the blockchain network continues to operate and the block height increases, the number of blocks that need to be synchronized when a new node reconstructs its state data also increases, as does the number of state database commits, resulting in increasingly longer state data reconstruction times for new nodes. For scenario three, which also requires state data reconstruction, the time consumed by the fault recovery node in rebuilding its state data is related to the number of blocks missing during the fault. In scenarios with high transaction volumes, a fault lasting several hours may cause a large number of missing blocks, requiring the fault recovery node to perform lengthy data synchronization and multiple state database commits to rebuild the state data.

[0005] There is currently no effective solution to the problem of low reconstruction efficiency of state data in blockchain technology due to the large number of blocks. Summary of the Invention

[0006] This application provides a method, apparatus, and storage medium for reconstructing state data based on blockchain, in order to solve the problem in related technologies where the reconstruction efficiency of state data is low due to the large number of blocks.

[0007] According to one aspect of this application, a method for reconstructing state data based on a blockchain is provided. The method includes: obtaining blocks from the blockchain that affect the state data of the blockchain, thus obtaining multiple first blocks; sequentially obtaining transaction data from the multiple first blocks, starting from the first block among the multiple first blocks; and reconstructing state data based on the obtained transaction data.

[0008] Optionally, obtaining multiple first blocks from the blockchain that affect the state data of the blockchain includes: determining whether each block on the blockchain stores transaction data; for blocks that store transaction data, determining whether the stored transaction data affects the state data; and if the stored transaction data affects the state data, determining that the block affects the state data and identifying the block as the first block.

[0009] Optionally, determining whether the stored transaction data affects the state data includes: obtaining the block number containing the transaction data and obtaining the version number of the state data, wherein the block number is the sequence number corresponding to the creation order of the block in the blockchain, and the version number is the number corresponding to the second block, which is the latest block created before the failure of the fault recovery node or a block newly added to the blockchain; determining whether the block number is greater than or equal to the version number, and if the block number is greater than or equal to the version number, determining that the stored transaction data affects the state data.

[0010] Optionally, starting from the first block among multiple first blocks, sequentially obtaining transaction data from multiple first blocks includes: sorting the first blocks in ascending order of their numbers to obtain a sorting result, where the number corresponds to the sequence number of the block's creation order in the blockchain; determining the first block ranked first in the sorting result as the starting block, and starting from the starting block, sequentially reading transaction data from multiple first blocks according to the order of the sorting result.

[0011] Optionally, reconstructing state data based on the acquired transaction data includes: determining the master node and slave nodes in the blockchain, wherein the master node is the node that begins reconstructing state data, and the slave nodes are nodes other than the master node; controlling the master node to reconstruct state data based on the acquired transaction data to obtain first state data, and uploading the first state data to the master node's state database; determining the master node's block, and updating the state data in each slave node based on the master node's block.

[0012] Optionally, updating the state data in each slave node according to the master node's blocks includes: synchronizing the master node's blocks to each slave node; controlling each slave node to obtain a first block from the master node's blocks, reconstructing state data based on the transaction data stored in the obtained first block to obtain second state data, and uploading the second state data to the slave node's state database.

[0013] Optionally, synchronizing blocks from the master node to each slave node includes: when the slave node is a node that has just joined the blockchain, synchronizing all blocks from the master node to the slave node; when the slave node is a fault recovery node, determining the number of the target block, obtaining the number of the target block and the newly created blocks after the target block from the master node, and synchronizing the obtained blocks to the slave node, wherein the target block is the latest block created before the fault recovery node failed.

[0014] According to another aspect of this application, a device for reconstructing state data based on a blockchain is provided. The device includes: a first acquisition unit, configured to acquire blocks from the blockchain that affect the state data of the blockchain, thereby obtaining multiple first blocks; a second acquisition unit, configured to sequentially acquire transaction data from the multiple first blocks, starting from a starting block among the multiple first blocks; and a reconstruction unit, configured to reconstruct state data based on the acquired transaction data.

[0015] According to another aspect of the present invention, a computer storage medium is also provided for storing a program, wherein the program, when running, controls the device where the computer storage medium is located to execute a method for reconstructing state data based on blockchain.

[0016] According to another aspect of the present invention, an electronic device is also provided, comprising one or more processors and a memory; the memory stores computer-readable instructions, and the processor is used to execute the computer-readable instructions, wherein the computer-readable instructions execute a method for reconstructing state data based on a blockchain.

[0017] This application employs the following steps: Firstly, blocks that influence the state data of the blockchain are obtained; secondly, transaction data from the first blocks is sequentially obtained, starting with the initial block; and thirdly, state data is reconstructed based on the obtained transaction data. This solves the problem of low reconstruction efficiency of state data due to the large number of blocks in related technologies. By selectively obtaining transaction data from blocks that influence the state data and reconstructing the state data based on this transaction data, the efficient reconstruction of state data is achieved. Attached Figure Description

[0018] The accompanying drawings, which form part of this application, are used to provide a further understanding of this application. The illustrative embodiments and descriptions of this application are used to explain this application and do not constitute an undue limitation of this application. In the drawings:

[0019] Figure 1 This is a flowchart of a blockchain-based state data reconstruction method provided in the embodiments of this application;

[0020] Figure 2 This is a schematic diagram illustrating the determination of the first block according to an embodiment of this application;

[0021] Figure 3 This is a flowchart of a blockchain-based state data reconstruction method according to an embodiment of this application;

[0022] Figure 4 This is a schematic diagram of a blockchain-based state data reconstruction device according to an embodiment of this application;

[0023] Figure 5 This is a schematic diagram of an electronic device provided according to an embodiment of this application. Detailed Implementation

[0024] 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.

[0025] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort should fall within the scope of protection of the present application.

[0026] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate for the embodiments of this application described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.

[0027] 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 display, data used for analysis, etc.) involved in this disclosure are all information and data authorized by the user or fully authorized by all parties.

[0028] According to an embodiment of this application, a method for reconstructing state data based on blockchain is provided.

[0029] Figure 1 This is a flowchart of a blockchain-based state data reconstruction method according to an embodiment of this application. Figure 1 As shown, the method includes the following steps:

[0030] Step S102: Obtain blocks from the blockchain that affect the state data of the blockchain, and obtain multiple first blocks.

[0031] Specifically, state data is a type of data that characterizes the metadata attributes in a block. The first block is the block that affects the metadata attributes. For example, the metadata is the transaction data of X at Bank Z, and the state data is the remaining deposit in X's wallet after this transaction. The first block is the block in which the transaction data affects the state data. For example, the transaction data in block 1 is the transaction before the deposit corresponding to the state data. The state database of the blockchain does not need to be updated, and block 1 is the block that has no impact on the state data. Block 2 is the transaction that occurred after the deposit corresponding to the state data. The state database of the blockchain needs to be updated, and block 2 is the block that affects the state data, which is the first block.

[0032] Step S104: Starting from the first block among the multiple first blocks, sequentially obtain the transaction data from the multiple first blocks.

[0033] Specifically, the starting block is the first block that affects the state data. For example, if blocks 2 and 3 are both first blocks, and the transaction data in block 3 affects the updated state data corresponding to block 2, then block 2 is the starting block.

[0034] Step S106: Reconstruct the status data based on the acquired transaction data.

[0035] Specifically, each first block will affect the state data, and the transaction data needs to be read sequentially according to the creation order of the first blocks to reconstruct the state data.

[0036] The blockchain-based state data reconstruction method provided in this application obtains multiple first blocks by retrieving blocks that influence the blockchain's state data. Starting from the first block, transaction data within each first block is sequentially retrieved. The state data is then reconstructed based on the retrieved transaction data. This method solves the problem of low reconstruction efficiency in related technologies due to the large number of blocks. By selectively retrieving transaction data from blocks that influence the state data and reconstructing the state data accordingly, it achieves highly efficient state data reconstruction.

[0037] Before reconstructing the state data, it is necessary to first determine the first block containing transaction data. Optionally, in the blockchain-based state data reconstruction method provided in this application embodiment, obtaining multiple first blocks from the blockchain that affect the state data of the blockchain includes: determining whether each block on the blockchain stores transaction data; for blocks that store transaction data, determining whether the stored transaction data affects the state data; and if the stored transaction data affects the state data, determining that the block has an impact on the state data and determining the block as the first block.

[0038] Specifically, blockchain blocks store different types of data, divided into blocks storing transaction data and blocks storing non-transaction data. For example, there are ordinary blocks storing transaction data and configuration blocks storing non-transaction data. Within the blocks storing transaction data, some blocks are designated as the first blocks. These first blocks influence the reconstruction of state data; for instance, transaction data stored in the first block updates the state data on nodes. Blocks other than the first block within the transaction data storage block do not affect the reconstruction of state data; for example, transaction data stored in a block does not update the state data on nodes. By identifying the first block containing transaction data, blocks without transaction data that do not affect the state data can be excluded, thereby improving the efficiency of state data reconstruction.

[0039] After identifying the block containing transaction data, it is also necessary to determine whether the block containing transaction data affects the state data. Optionally, in the blockchain-based state data reconstruction method provided in this application embodiment, determining whether the stored transaction data affects the state data includes: obtaining the number of the block containing transaction data and obtaining the version number of the state data, wherein the number is the sequence number corresponding to the creation order of the block in the blockchain, the version number is the number corresponding to the second block, and the second block is the latest block created before the failure of the fault recovery node or a newly added block to the blockchain; determining whether the number is greater than or equal to the version number, and if the number is greater than or equal to the version number, determining that the stored transaction data affects the state data.

[0040] Specifically, the block number is a marker on each node of the blockchain, determined according to the order of block creation. State data is updated as blocks storing transaction data are created. The second block is the last block to update state data before state data reconstruction. Since state data reconstruction can occur in different scenarios, the second block could be the most recently created block before a faulty recovery node failed, or a block newly added to the blockchain by a new node. By determining whether the transaction data stored in a block affects the state data, parts of the first block that do not affect the state data can be excluded, thereby improving the efficiency of state data reconstruction.

[0041] For example, in scenarios where a node fails and needs to rebuild its state data, Figure 2 This is a schematic diagram of determining the first block according to an embodiment of this application, such as... Figure 2 As shown, before the failure, the node's state data was A=10, version number=4; state data was B=20, version number=6. Traversal begins from the genesis block. The genesis block contains no transaction data and is marked as having no contribution, meaning the data in the genesis block will not update the node's state data.

[0042] Next, we traversed to block number 1 and extracted two transaction data. From transaction 1, we extracted transaction data about A. A version number of A was found to be 4 in the state database, which is not equal to block number 1. This indicates that transaction 1 did not contribute to the final version of A; that is, transaction 1 was a transaction that updated the state data before the failure occurred. From transaction 2, we extracted transaction data about B. A version number of B was found to be 6 in the state database, which is not equal to block number 1. This indicates that transaction 2 did not contribute to the final version of B; that is, transaction 2 was a transaction that updated the state data before the failure occurred. In short, block number 1 did not contribute to the final version of the state data.

[0043] This process continues until block number 4, where transaction 3 is extracted. From transaction 3, transaction data about A is extracted. The state database shows A's version number as 4, which equals the current block number. This indicates that transaction 3 contributes to the final version of the state data; that is, transaction 3 was the last transaction to update the state data when the node failed. Therefore, block number 4 contributes to the final version of the state data, while blocks numbered 0 to 3 do not. The process continues until block number 6, where transaction 4 is extracted. From transaction 4, transaction data about B is extracted. The state database shows B's version number as 6, which equals the current block number. This indicates that transaction 4 contributes to the final version of the state data; that is, transaction 4 was the last transaction to update the state data when the node failed. Therefore, block number 6 contributes to the final version of the state data, while block number 5 does not. Starting from block number 4, transaction data is replayed to reconstruct the state data.

[0044] When reconstructing state data, it is necessary to determine the order in which transaction data in the blocks are read. Optionally, in the blockchain-based state data reconstruction method provided in this application embodiment, starting from the starting block among multiple first blocks, the transaction data in multiple first blocks are obtained sequentially, including: sorting the first blocks in ascending order of their numbers to obtain a sorting result, wherein the number is the sequence number corresponding to the creation order of the blocks in the blockchain; determining the first block ranked first in the sorting result as the starting block, and starting from the starting block, reading the transaction data in multiple first blocks sequentially according to the order of the sorting result.

[0045] Specifically, the starting block is the block with the smallest number among multiple first blocks. The starting block's number is equal to the version number of the state data. Blocks with numbers larger than the starting block correspond to transactions generated after a failure. After updating the state data by reading transaction data from the starting block, transaction data from multiple first blocks is read sequentially according to the sorting result. Transaction data from each first block updates the state data. Using transaction data from multiple first blocks to update the state data is more efficient than retrieving data from all blocks on the blockchain.

[0046] After determining the order in which transaction data in the block is read, it is also necessary to update the state database of the master node based on the transaction data. Optionally, in the blockchain-based state data reconstruction method provided in this application embodiment, reconstructing state data based on the acquired transaction data includes: determining the master node and slave nodes in the blockchain, wherein the master node is the node that starts reconstructing state data, and the slave nodes are nodes other than the master node; controlling the master node to reconstruct state data based on the acquired transaction data to obtain first state data, and uploading the first state data to the state database of the master node; determining the block of the master node, and updating the state data in each slave node based on the block of the master node.

[0047] Specifically, each new organization joining the blockchain establishes its own master node within the blockchain network. When a new organization needs to scale, it establishes slave nodes based on the master node. When a new organization joins the blockchain or when an organization's node fails, the state data needs to be rebuilt. When a new organization joins the blockchain, its master node obtains initial state data from the nodes of other organizations, and the slave nodes rebuild their state data based on the master node's initial state data. After the state data is rebuilt, the new organization establishes new state data based on newly added transaction data. When an organization's slave node fails, it obtains the state data of the most recently created block before the failure and the state data of all new blocks after the failure from the organization's master node, thus completing the reconstruction of the failed node's state data. By updating the master node's state database, the blockchain's state data can be restored, allowing the blockchain network to operate normally.

[0048] After the master node's state database is updated, the slave node's state database also needs to be updated. Optionally, in the blockchain-based state data reconstruction method provided in this application embodiment, updating the state data in each slave node according to the master node's block includes: synchronizing the master node's block to each slave node; controlling each slave node to obtain a first block from the master node's block, reconstructing state data according to the transaction data stored in the obtained first block to obtain second state data, and uploading the second state data to the slave node's state database.

[0049] Specifically, the blocks of the slave nodes are obtained from the master node. The master node synchronizes the data of all blocks on its node to the slave nodes. The slave nodes build their own blocks based on the synchronized data. The slave nodes' state data is directly reconstructed by reading the transaction data from the first block of the master node to obtain the second state data. Updating the state database of the slave nodes allows clients to use the blockchain network normally.

[0050] When updating the state database of a slave node, it is necessary to synchronize the blocks of the master node to each slave node. Optionally, in the blockchain-based state data reconstruction method provided in this application embodiment, synchronizing the blocks of the master node to each slave node includes: when the slave node is a node that has just joined the blockchain, synchronizing all blocks of the master node to the slave node; when the slave node is a fault recovery node, determining the number of the target block, obtaining the number of the target block and the newly created blocks after the target block from the master node, and synchronizing the obtained blocks to the slave node, wherein the target block is the latest block created before the fault recovery node failed.

[0051] Specifically, when a slave node joins the blockchain for the first time, it needs to obtain data from all blocks on the master node. When a slave node is a fault recovery node, it only needs to obtain data from the blocks added after the fault recovery node failed, as well as data from the most recently created block before the failure, to reconstruct the state data. By synchronizing the master node's blocks to each slave node, the slave node's state data can be quickly reconstructed.

[0052] According to an embodiment of this application, a method for reconstructing state data based on blockchain is provided.

[0053] Figure 3 This is a flowchart of a blockchain-based state data reconstruction method according to an embodiment of this application. Figure 3 As shown, the method includes the following steps:

[0054] Step S301: When the master node submits the state database, it calculates the minimum contributing block number.

[0055] Specifically, the initial value of the minimum contributing block number is set to 0. Each time a block is committed to the state database, it is determined whether the current block type is a configuration block. If the current block type is a configuration block, it is determined whether the current minimum contributing block number is equal to the configuration block number. If the current minimum contributing block number is equal to the configuration block number, the minimum contributing block number is set to the configuration block number + 1. If the current block type is a regular block, it is determined whether the version of all transactions in the current minimum contributing block in the state database is greater than the current minimum contributing block number. If the version of all transactions in the current minimum contributing block in the state database is greater than the current minimum contributing block number, the minimum contributing block number is set to the regular block number + 1.

[0056] For example, if the minimum contributing block number is 0, after submitting block number 0, the block type is determined to be a configuration block, and since the minimum contributing block number is 0, the minimum contributing block number is 1. After submitting block number 1, the block type is determined to be a normal block. Transaction data about C and D is extracted from the minimum contributing block (block number 1). The state database shows that the version number of C is 1 and the version number of D is 1, so the loop is broken. After submitting block number 2, the block type is determined to be a normal block. Transaction data about C and D is extracted from the minimum contributing block (block number 1). The state database shows that the version number of C is 2 and the version number of D is 1, so the loop is broken. After submitting block number 3, the block type is determined to be a normal block. Transaction data about C and D is extracted from the minimum contributing block (block number 1). The state database shows that the version number of C is 2 and the version number of D is 3, so the minimum contributing block number is 2. Continue extracting transaction data about C from the smallest contributing block (number = 2). Find the version number of C in the state database as 2, and exit the loop.

[0057] After submitting block number 4, the block type is determined to be a normal block. Transaction data about C is extracted from the smallest contributing block (block number = 2). The version number of C is found to be 4 in the state database, therefore the smallest contributing block number is 3. Transaction data about D is then extracted from the smallest contributing block (block number = 3). The version number of D is found to be 3 in the state database, and the loop is exited. After submitting block number 5, the block type is determined to be a configuration block. The smallest contributing block (block number = 3) is not equal to 5, so the loop is exited. After submitting block number 6, the block type is determined to be a normal block. Transaction data about D is extracted from the smallest contributing block (block number = 3). The version number of D is found to be 6 in the state database, therefore the smallest contributing block number is 4. Continue extracting transaction data about C from the smallest contributing block (block number = 4). The state database shows C's version number as 4, so the loop exits. After committing block number 7, it checks if the block type is a configuration block. Since the smallest contributing block (block number = 4) is not equal to 7, the loop exits again. The smallest contributing block number is recorded in the master node's local state database.

[0058] Step S302: The slave node queries the master node for the smallest contributing block number.

[0059] Specifically, before requesting data synchronization service from the master node, the slave node first queries the smallest contributing block number and records it in the slave node's local state database.

[0060] Step S303: The slave node requests the data synchronization service from the master node.

[0061] Specifically, consistent with existing technology, slave nodes request data synchronization services from the master node based on their local block height. Newly joined slave nodes send a starting block number of 0; recovered slave nodes send a starting block number equal to their local block height. The master node then pushes blocks to the slave nodes starting from the starting block number.

[0062] Step S304: Reconstruct from node state data.

[0063] Specifically, it determines whether the current block type is a configuration block. If the current block type is a configuration block, the configuration block is executed to complete the reconstruction of the slave node's state data. If the current block type is a normal block, it determines whether the current block number is less than the minimum contributing block number. If the current block number is less than the minimum contributing block number, the block is skipped, and the next block is determined. If the current block number is greater than or equal to the minimum contributing block number, the state data of the block is committed to complete the reconstruction of the slave node's state data.

[0064] Step S305: Calculate the minimum contributing block number when the node submits the state database.

[0065] Specifically, since a slave node may switch to a master node, when a slave node submits its state database, it needs to calculate the minimum contributing block number, just like the master node. When a slave node switches to a master node, the processing method is the same as that of the original master node. This application provides a blockchain state data reconstruction method based on state data versions. Nodes do not need to submit state data starting from the genesis block; they only need to submit blocks starting from the minimum contributing block, thus shortening the state data reconstruction time and improving state data reconstruction efficiency.

[0066] It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and although a logical order is shown in the flowchart, in some cases the steps shown or described may be executed in a different order than that shown here.

[0067] This application also provides a blockchain-based state data reconstruction apparatus. It should be noted that this blockchain-based state data reconstruction apparatus can be used to execute the blockchain-based state data reconstruction method provided in this application. The following describes the blockchain-based state data reconstruction apparatus provided in this application.

[0068] Figure 4 This is a schematic diagram of a blockchain-based state data reconstruction apparatus according to an embodiment of this application. Figure 4 As shown, the device includes: a first acquisition unit 401, used to acquire blocks that affect the state data of the blockchain from the blockchain, and obtain multiple first blocks; a second acquisition unit 402, used to acquire transaction data in multiple first blocks sequentially, starting from the starting block among the multiple first blocks; and a reconstruction unit 403, used to reconstruct state data based on the acquired transaction data.

[0069] The blockchain-based state data reconstruction apparatus provided in this application embodiment obtains multiple first blocks by first acquisition unit 401 acquiring blocks that affect the state data of the blockchain; second acquisition unit 402 acquires transaction data from multiple first blocks sequentially, starting from the first block; and reconstruction unit 403 reconstructs the state data based on the acquired transaction data. This solves the problem in related technologies where the reconstruction efficiency of state data is low due to the large number of blocks. By selectively acquiring transaction data from blocks that affect the state data and reconstructing the state data based on the transaction data, the apparatus achieves efficient reconstruction of the state data.

[0070] Optionally, in the blockchain-based state data reconstruction apparatus provided in this application embodiment, the first acquisition unit 401 includes: a first judgment module, used to judge whether transaction data is stored in each block on the blockchain; a second judgment module, used to judge whether the stored transaction data affects the state data for a block that stores transaction data; and a first determination module, used to determine that the block has an impact on the state data when the stored transaction data affects the state data, and to determine the block as the first block.

[0071] Optionally, in the blockchain-based state data reconstruction apparatus provided in this application embodiment, the second judgment module includes: a first acquisition submodule, used to acquire the number of the block storing transaction data and acquire the version number of the state data, wherein the number is the sequence number corresponding to the creation order of the block in the blockchain, the version number is the number corresponding to the second block, and the second block is the latest block created before the failure of the fault recovery node or a block newly added to the blockchain; and a judgment submodule, used to determine whether the number is greater than or equal to the version number, and if the number is greater than or equal to the version number, to determine that the stored transaction data affects the state data.

[0072] Optionally, in the blockchain-based state data reconstruction apparatus provided in this application embodiment, the second acquisition unit 402 includes: a sorting module, used to sort the first blocks in ascending order of their numbers to obtain a sorting result, wherein the number is the sequence number corresponding to the creation order of the blocks in the blockchain; and a second determining module, used to determine the first block ranked first in the sorting result as the starting block, and starting from the starting block, sequentially read the transaction data in multiple first blocks in the order of the sorting result.

[0073] Optionally, in the blockchain-based state data reconstruction apparatus provided in this application embodiment, the reconstruction unit 403 includes: a third determining module, used to determine the master node and slave nodes in the blockchain, wherein the master node is the node that starts reconstructing the state data, and the slave nodes are nodes other than the master node; a reconstruction module, used to control the master node to reconstruct the state data according to the acquired transaction data, obtain the first state data, and upload the first state data to the master node's state database; and a fourth determining module, used to determine the master node's block and update the state data in each slave node according to the master node's block.

[0074] Optionally, in the blockchain-based state data reconstruction apparatus provided in this application embodiment, the fourth determining module includes: a synchronization submodule, used to synchronize the blocks of the master node to each slave node; and a second acquisition submodule, used to control each slave node to acquire a first block from the blocks of the master node, reconstruct state data according to the transaction data stored in the acquired first block, obtain second state data, and upload the second state data to the state database of the slave node.

[0075] Optionally, in the blockchain-based state data reconstruction apparatus provided in this application embodiment, the synchronization submodule includes: a block synchronization submodule, used to synchronize all blocks in the master node to the slave node when the slave node is a node that has just joined the blockchain; and a number determination submodule, used to determine the number of the target block when the slave node is a fault recovery node, obtain the number of the target block and the newly created blocks after the target block from the master node, and synchronize the obtained blocks to the slave node, wherein the target block is the latest block created before the fault recovery node failed.

[0076] The aforementioned state data reconstruction device based on blockchain includes a processor and a memory. The first acquisition unit 401, the second acquisition unit 402, and the reconstruction unit 403 are all stored in the memory as program units. The processor executes the aforementioned program units stored in the memory to realize the corresponding functions.

[0077] The processor contains a kernel, which retrieves the corresponding program unit from memory. One or more kernels can be configured, and by adjusting kernel parameters, the efficient reconstruction of state data can be achieved.

[0078] The memory may include non-permanent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.

[0079] This application also provides a computer storage medium for storing a program, wherein the program, when running, controls the device where the computer storage medium is located to execute a method for reconstructing state data based on blockchain.

[0080] like Figure 5 As shown in the illustration, this application also provides an electronic device 501, which includes a processor, a memory, and a program stored in the memory and executable on the processor. When the processor executes the program, it performs the following steps: reconstruction of state data based on blockchain. The device in this document can be a server, PC, PAD, mobile phone, etc.

[0081] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0082] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.

[0083] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.

[0084] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.

[0085] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.

[0086] Memory may include non-persistent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.

[0087] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.

[0088] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.

[0089] The above are merely embodiments of this application and are not intended to limit the scope of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of the claims of this application.

Claims

1. A method for reconstructing state data based on a blockchain, characterized by, The method comprises the following steps: Obtaining a plurality of first blocks from the blockchain which have an impact on the state data of the blockchain, comprising: judging whether each block on the blockchain stores transaction data; for the block storing the transaction data, judging whether the stored transaction data affects the state data; in the case that the stored transaction data affects the state data, determining that the block has an impact on the state data, and determining the block as a first block; Wherein, judging whether the stored transaction data affects the state data comprises: obtaining the number of the block storing the transaction data, and obtaining the version number of the state data, wherein the number is the serial number corresponding to the creation order of the block in the blockchain, and the version number is the number corresponding to the second block, which is the latest block created before the fault recovery node fails or the block newly added to the blockchain; judging whether the number is greater than or equal to the version number, and in the case that the number is greater than or equal to the version number, determining that the stored transaction data affects the state data; Starting from the starting block in the plurality of first blocks, transaction data in the plurality of first blocks is obtained in sequence, wherein the starting block is the first block which has an impact on the state data; Reconstructing the state data according to the obtained transaction data.

2. The method of claim 1, wherein, Starting from the starting block in the plurality of first blocks, transaction data in the plurality of first blocks is obtained in sequence, comprising: The first blocks are sorted in ascending order of number to obtain a sorting result, wherein the number is the serial number corresponding to the creation order of the block in the blockchain; The first block ranked first in the sorting result is determined as the starting block, and the transaction data in the plurality of first blocks is read in sequence according to the order of the sorting result starting from the starting block.

3. The method of claim 1, wherein, Reconstructing the state data according to the obtained transaction data comprises: Determining the master node and the slave node in the blockchain, wherein the master node is the node starting to reconstruct the state data, and the slave node is the node other than the master node; Controlling the master node to reconstruct the state data according to the obtained transaction data to obtain first state data, and uploading the first state data to the state database of the master node; Determining the block of the master node, and updating the state data in each slave node according to the block of the master node.

4. The method of claim 3, wherein, Updating the state data in each slave node according to the block of the master node comprises: Synchronizing the block of the master node to each slave node; Controlling each slave node to obtain the first block from the block of the master node, reconstructing the state data according to the transaction data stored in the obtained first block to obtain second state data, and uploading the second state data to the state database of the slave node.

5. The method of claim 4, wherein, Synchronizing the block of the master node to each slave node comprises: In the case that the slave node is a node which is newly added to the blockchain, synchronizing all blocks in the master node to the slave node; In a case where the slave node is a fault recovery node, a number of a target block is determined, the number of the target block and a newly created block after the target block are obtained from the master node, and the obtained blocks are synchronized to the slave node, wherein the target block is a latest created block before the fault recovery node fails. 6.A reconstruction apparatus of state data based on a blockchain, characterized by, Comprise: A first obtaining unit is configured to obtain, from a block chain, blocks that have an influence on state data of the block chain, to obtain a plurality of first blocks. The first obtaining unit comprises: a first judging module configured to judge whether transaction data is stored in each block on the block chain; a second judging module configured to, for a block storing the transaction data, judge whether the stored transaction data influences the state data; and a first determining module configured to, in a case where the stored transaction data influences the state data, determine that the block has an influence on the state data, and determine the block as a first block; The second judging module comprises: a first obtaining submodule configured to obtain a number of a block storing the transaction data, and obtain a version number of the state data, wherein the number is a serial number corresponding to a creation order of a block in the block chain, and the version number is a number corresponding to a second block, the second block being a latest created block before a fault recovery node fails or a block newly added to the block chain; and a judging submodule configured to judge whether the number is greater than or equal to the version number, and determine that the stored transaction data influences the state data in a case where the number is greater than or equal to the version number; A second obtaining unit is configured to, taking a starting block in the plurality of first blocks as a starting point, sequentially obtain transaction data in the plurality of first blocks, wherein the starting block is a first block that has an influence on the state data; A reconstruction unit is configured to reconstruct the state data according to the obtained transaction data.

7. A computer storage medium, characterized in that The computer storage medium is configured to store a program, wherein the program, when executed, controls a device where the computer storage medium is located to perform the reconstruction method of the state data based on the block chain according to any one of claims 1 to 5.

8. An electronic device, comprising: Comprise one or more processors and a memory, the memory is configured to store one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors are caused to implement the reconstruction method of the state data based on the block chain according to any one of claims 1 to 5.

Citation Information

Patent Citations

  • Block chain state data recovery method and device and electronic equipment

    CN110471795A

  • Incompatible block chain upgrading system and method based on data playback and medium

    CN113065867A

  • Block chain data updating method and system

    CN113271365A