Method and system for asynchronous storage of state data
By adopting the asynchronous storage method of state data in the blockchain, using the latest version of cache and persistent storage to build data copies for reading and writing, and improving data retrieval efficiency through the Bloom filter, the state data writing in the blockchain is solved IO resources and time-consuming issues improve transaction throughput and ensure data accuracy and recovery capabilities.
Patent Information
- Application Number
- CN202410992439.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-23
- Publication Date
- 2024-11-26
- Estimated Expiration
- 2044-07-23
AI Technical Summary
In blockchain, the writing process of state data requires a lot of IO resources and time, limiting the transaction throughput of the blockchain, and may lead to the reading of new and old blocks caused by the failure of cached data to complete persistent storage in a timely manner. The write status data conflicts, resulting in inconsistent or incorrect execution results.
The state data asynchronous storage method is adopted. After the new block consensus is passed, the block data is stored persistently and the state data is written to the cache first. The state data in the cache is stored asynchronously and persistently, and the cache and persistent storage are used. The latest version builds a copy of data for reading and writing, and improves data retrieval efficiency through Bloom filters to avoid loss of state data caused by node downtime.
It improves blockchain transaction throughput, avoids the problem of inconsistent or incorrect blockchain state execution results, and at the same time, it realizes state data recovery after node downtime, ensuring the correctness of data persistent storage.
Smart Images

Figure CN119025530A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of blockchain, and in particular relates to a method and system for asynchronous storage of state data. Background Art
[0002] The statements in this section merely provide background information related to the present invention and do not necessarily constitute prior art.
[0003] Blockchain technology is a distributed ledger technology composed of multiple technologies such as peer-to-peer communication, cryptographic algorithms, smart contracts, and consensus mechanisms. It has the characteristics of openness, transparency, non-tamperability, non-repudiation, and traceability. The data on the blockchain usually includes block data and status data. The block data adopts a block chain data structure, including a block header and a block body. The block header contains the hash value prehash of the previous block, the hash value of the current block body, the status root of the current block, and timestamp information. The block body contains the transaction records contained in the current block, and the block height of each block increases based on the time series relationship. As new blocks are generated, the status data read and written by the transactions in the block will change, and the changed status data will be persistently stored on the disk or storage medium as the new blockchain is uploaded.
[0004] In the blockchain, in order to ensure the consistency and correctness of data, the blockchain node will not start the next round of consensus or block execution until the block data and status data that have passed the consensus have completed persistent storage; otherwise, the status data used when the next block reads and writes the status data may not be the latest data due to conflicts between the previous and next block reads and writes data, resulting in inconsistent or incorrect execution results.
[0005] When block data is uploaded to the chain, the writing process of status data consumes more IO resources and time, which limits the transaction throughput of the blockchain. Summary of the invention
[0006] In order to solve the above problems, the present invention proposes a method and system for asynchronous storage of state data, which can avoid the loss of state data after abnormal node downtime caused by the state data caching mechanism, reduce the new block processing blockage caused by persistent storage of state data, improve the blockchain transaction throughput while avoiding inconsistent or incorrect blockchain state execution results.
[0007] According to some embodiments, the present invention adopts the following technical solutions:
[0008] A method for asynchronously storing state data comprises the following steps:
[0009] After the consensus of the new block is passed, the block data is persistently stored and the status data is first written to the cache. The status data in the cache is asynchronously persistently stored.
[0010] In the above process, when a request for reading or writing state data is received, a data copy is constructed based on the latest version of the state data in the cache and persistent storage and then read or write is performed.
[0011] As an optional implementation, before writing the status data into the cache, all write data related to the change, addition or deletion of the status data are formed into a status data set, and a Bloom filter is constructed based on the identifier of the status data. The status data set is written into the status cache queue in batches with the block height n of the block as the version, and the Bloom filter corresponding to the version of the status data set is written into the Bloom filter cache.
[0012] As an optional implementation method, the process of completing persistent storage of block data is to determine whether the current block consensus has passed according to the consensus rules, and after reaching the persistent chain state, the block data and the current block height are persistently stored.
[0013] As an optional implementation, the process of asynchronously persisting the state data in the cache includes: asynchronously persisting the state data sets of each version in the state cache queue in order from low to high versions according to the version number size, deleting the cached state data set of that version from the state cache queue after each persistent storage, deleting the Bloom filter of that version from the Bloom filter cache, updating the block height of the currently completed state data persistent storage in the persistent storage, and starting the persistent storage of the next version of the state data set until there is no data to be persisted in the state cache queue.
[0014] As an optional implementation, the state data of the block data is written into the state cache queue, and the construction, consensus or block execution of the next block can be started without waiting for the data in the state cache queue to be persisted.
[0015] As an optional implementation, if the construction, consensus or execution process of a new block requires reading and writing state data, the Bloom filters of the cached state data sets of each version are searched in order from high version to low version until the highest version state data set cache where the required data may exist is located, and the data is obtained from it;
[0016] If the required data does not exist in any of the cached versions of the status data, the latest version of the required data is in the persistent storage, and the required data is obtained from the persistent status data.
[0017] As an optional implementation method, the write data identifiers that are changed, added or deleted during the reading and writing process after the data copy is built are collected in the block's pending status data set, and a Bloom filter is built based on the identifiers of the above changed, added or deleted write data.
[0018] A method for node crash recovery of asynchronous storage of state data. Based on the above method for asynchronous storage of state data, when the node restarts after a crash, the cached state data that failed to be persistently stored when the node crashed is recovered from the block data persistently stored by the node, and the missing state data is persistently stored.
[0019] As an alternative implementation, the process of recovering the cached state data that failed to be persistently stored when the node crashed from the block data persistently stored by the node includes: obtaining the current block height a of this node from persistent storage and the block height b at which this node has currently completed persistent storage of state data. If b < a, it indicates that there is state data that was not persistently stored when this node crashed;
[0020] The node obtains the next block after the block at which this node has currently completed persistent storage of state data from persistent storage, replays the transactions in the next block, calculates the state root based on the obtained state data, and compares it with the state root recorded in the next block. If they are equal, it indicates that the state execution is correct, and the state data is stored in persistent storage;
[0021] The re - execution and persistent storage of the state data of the remaining blocks are completed in sequence according to the above steps to achieve the recovery of state data.
[0022] As an alternative implementation, if the state root obtained during the recovery process of state data is inconsistent with the state root recorded in the block data, discard the block and subsequent blocks with higher block heights, request to synchronize the missing block data from other nodes in the network, and re - verify and execute until the block heights are equal.
[0023] A system for asynchronous storage of state data, including at least one blockchain node, and the blockchain node includes:
[0024] A block processing module, configured to construct, execute, and perform consensus verification on blocks based on blockchain communication rules and consensus rules, and persistently store the block data passed by consensus;
[0025] A state data caching module, configured to write the state data into the cache first after the new block passes consensus, cache the set of block state data to be persistently stored with the block height as the version, asynchronously persistently store the state data of each version in the cache; when receiving a request for reading and writing state data, construct a data copy based on the latest version of the state data in the cache and persistent storage and then perform reading and writing.
[0026] As an alternative implementation, the blockchain node further includes a state execution engine module, and the state execution engine module includes:
[0027] The state data execution module is configured to form a state data set with all write data related to changes, additions or deletions of the state data before writing the state data into the cache;
[0028] A Bloom filter construction module, configured to construct a Bloom filter based on the identifier of the state data;
[0029] The state root calculation module is configured to calculate the state root of the block based on the write data collected by the state data execution module, and submit it to the block processing module for block verification.
[0030] As an optional implementation, the state data cache module includes:
[0031] The state data cache queue is configured to use a queue structure with a first-in-first-out cache state execution engine module to cache the state data set of each block version to be persisted;
[0032] The state data asynchronous storage module is configured to sequentially obtain a version of the state data set to be persisted from the state data cache queue and store it persistently. After completing the persistent storage of a version of the state data set, the state data set is deleted from the state data cache queue, the Bloom filter of the version data is deleted from the latest version state data acquisition module, and the block height of the currently completed state data persistent storage in the persistent storage is updated;
[0033] The latest version status data acquisition module is configured to retrieve the latest version of the status data required for block status execution based on the Bloom filter of each version of the status data to be persisted, and create a data copy based on the retrieved data.
[0034] A node crash recovery system for asynchronous storage of state data includes at least one blockchain node, wherein the blockchain node includes:
[0035] The state data recovery module is configured to recover the cached state data that failed to complete persistent storage when the node crashed based on the block data persistently stored in the node when the node crashed and restarted, and complete persistent storage of the missing state data.
[0036] As an optional implementation, the state data recovery module includes:
[0037] The missing judgment module is configured to check whether the persistent state data of the node is missing based on the current block height of the persistently stored node and the block height of the currently completed state data persistence;
[0038] The replay execution module is configured to replay the block data starting from the block height of the minimum version of the missing state data, and calculate the state root based on the executed state data to verify whether it is equal to the state root in the block data. If equal, the state data set is persistently stored until it reaches the current block height.
[0039] As an optional implementation, it also includes a block synchronization module, which is configured to synchronize missing blocks from other nodes of the blockchain, and execute, verify and store them on the chain until the current block height in the blockchain system is reached.
[0040] Compared with the prior art, the present invention has the following beneficial effects:
[0041] The present invention uses block height as version to maintain the state data cache to be persistently stored. When the state data is written into the cache, the state processing of the next block can be started. The state data in the cache is persisted asynchronously, thereby reducing the new block processing blockade caused by the persistent storage of the state data and improving the blockchain transaction throughput.
[0042] The present invention supports reading and writing state data during block processing, and reads and writes after building a data copy based on the latest version of the state data in the cache and persistent storage, so as to avoid inconsistent or incorrect results of the new block when the read and write state data of the new and old blocks conflict due to the failure to complete the persistent storage of the cached data in time; on the other hand, the method of building a data copy does not change the cached historical block state data, and does not affect the correctness of the persistent storage of the historical block state data.
[0043] When the present invention obtains the latest version of status data based on the cache, the data retrieval efficiency is improved based on the Bloom filter.
[0044] The present invention stores the current block height of the blockchain node and the block height of the completed state data persistence in real time, and based on this, provides a state data recovery mechanism for node crashes. Even if the node crash causes the loss of cached state data, the state data can be restored based on the block data.
[0045] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, preferred embodiments are given below and described in detail with reference to the accompanying drawings. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] The accompanying drawings in the specification, which constitute a part of the present invention, are used to provide a further understanding of the present invention. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute improper limitations on the present invention.
[0047] Figure 1 is a flow chart of a method for asynchronous storage of state data according to an embodiment;
[0048] Figure 2 This is a schematic diagram of a version update process of an embodiment;
[0049] Figure 3 is a data flow diagram of asynchronous storage of state data of an embodiment;
[0050] Figure 4 The present invention is a flowchart of a node downtime recovery method for asynchronous storage of state data in an embodiment;
[0051] Figure 5 This is a schematic diagram of a blockchain node with asynchronous storage of state data in one embodiment. DETAILED DESCRIPTION
[0052] The present invention will be further described below in conjunction with the accompanying drawings and embodiments.
[0053] It should be noted that the following detailed descriptions are all illustrative and intended to provide further explanation of the present invention. Unless otherwise specified, all technical and scientific terms used herein have the same meanings as those commonly understood by those skilled in the art to which the present invention belongs.
[0054] It should be noted that the terms used herein are only for describing specific embodiments and are not intended to limit exemplary embodiments according to the present invention. As used herein, unless the context clearly indicates otherwise, the singular form is also intended to include the plural form. In addition, it should be understood that when the terms "comprising" and / or "including" are used in this specification, it indicates the presence of features, steps, operations, devices, components and / or combinations thereof.
[0055] In the absence of conflict, the embodiments in this application and the features in the embodiments may be combined with each other.
[0056] Embodiment 1
[0057] A method for asynchronous storage of state data, such as Figure 1 As shown, the following steps are included:
[0058] Step 101: New block construction, execution and consensus status data collection, blockchain nodes block a new block with a block height of n n During the construction, execution and consensus of the state data, all write data related to the change, addition or deletion of the state data constitutes the state data set state_set n The above state data identifies the construction of the Bloom filter bl oom_filter n .
[0059] The new block construction, execution and consensus process requires the reading and writing of state data by obtaining the latest version from the cached state data set and persistent storage, and then building a data copy to read and write data.
[0060] The Bloom filter mentioned above is a data structure with high space efficiency and low time complexity. It is used to determine whether an element belongs to a set and can give the result that the element may or definitely does not exist in the set.
[0061] The specific process is as follows Figure 2 As shown, steps 1001-1009 are included:
[0062] Step 1001: Obtain the highest version number of the current cached state set as the initial version number of the cache retrieval.
[0063] Step 1002: Retrieve the data identifier from the Bloom filter of this version in the cache.
[0064] Step 1003: Determine the return value of the Bloom filter. If it is true, it means that the data may exist in the cached status data set of this version, and go to step 1004; if it is false, it means that the data definitely does not exist in the cached status data set of this version, and go to step 1006.
[0065] Step 1004: Try to obtain data from the state data set of the version in the cache.
[0066] Step 1005: Determine whether data is obtained in step 1004, if so, proceed to step 1007, otherwise proceed to step 1006.
[0067] Step 1006: Determine whether the current version is the lowest version in the cache, if so, proceed to step 1008, otherwise proceed to step 1009.
[0068] Step 1007: Create a data copy based on the data acquired in step 1005 to perform read and write operations.
[0069] Step 1008: Retrieve data from persistent storage to perform data read and write operations.
[0070] Step 1009: Subtract 1 from the current version number and proceed to step 1002 to continue the data retrieval process.
[0071] Step 102: The new block data is persisted. When the blockchain node determines the block block according to the consensus rules, n After consensus is passed and the persistent state is reached, the block data will be blocked_data n , the current block height currentBH=n is stored persistently.
[0072] Step 103: Write the state data set to the cache and write the state data set to be submitted state_set n Take the block height n of the block as the version, write it into the status cache queue in batches, and write the block_filter corresponding to the status data set of this version n Write to the Bloom filter cache.
[0073] Step 104: Asynchronously persist the state data set, and store each version of the state data set state_set in the state cache n-m to state_set n Asynchronously, the version number is stored in order from the lowest version to the highest version. Each time a version state data set is completed, state_set k If the persistent storage is deleted, the cached state data set state_set of this version is deleted from the state cache queue. k , delete the version of the Bloom filter from the Bloom filter cache bl oom_filter k , Update the block height stateBH=k of the currently completed state data persistent storage in the persistent storage, and start the persistent storage of the next version of the state data set until there is no data to be persisted in the state cache queue.
[0074] The blockchain node will state_set n After writing to the state cache queue, you don’t have to wait for the data in the state cache queue to be persisted before starting the next block block. n+1 structuring, execution and consensus.
[0075] If the next block is blocked n+1 The construction, execution and consensus process requires reading and writing state data state x , then search from the Bloom filters of each version of the cached state data set from high version to low version in sequence until the highest version of the state data set cache state_set where the required data may exist is located x and from state_set x Get data from the cache. If the required data does not exist in any of the cached version status data, it means that the latest version of the required data is in the persistent storage, and the required data is obtained from the persistent status data.
[0076] Get the data state x Then copy the data replica state based on the data x’ Perform data read and write operations, including changes, additions, or deletions of write data markers that are grouped into blocks.n+1 The state data set to be submitted state_set n+1 In the above, a Bloom filter is constructed based on the identifier of the changed, added or deleted write data. n+1 .
[0077] like Figure 3 As shown, in this embodiment, data1-235 represents the 235 cache version of the state data data1, and data1-db represents the persistent storage version of data1.
[0078] The state cache queue has versions 235, 236, and 237 waiting to be written to persistent storage. The state data set of version 235 contains data1-235 and data2-235; the state data set of version 236 contains data3-236; the state data set of version 237 contains data1-237 and data4-237. The persistent database contains persistent data such as data1-db, data2-db, data3-db, data4-db, data5-db, and data6-db.
[0079] During the construction, execution and consensus of the new block 238, it is necessary to read and write data data1, data2, and data6. The latest version of data1 is in the cache status data set of version 237, the latest version of data2 is in the cache status data set of version 235, and the latest version of data6 is in persistent storage. Based on the above data, data copies data1-237', data2-235', and data6-db' are respectively constructed for data reading and writing during the new block processing. Among them, data1-237' and data6-db' perform data write operations during data processing, and data1-237' and data6-db' are collected into the write operation status data set of version 238 as data1-238 and data6-238, and the version status data set is written into the cache queue.
[0080] The state data sets of each version in the state data cache queue are persistently stored in order from low version to high version according to the version size. The process does not affect the processing of new blocks, and the reading and writing of state data by new blocks does not affect the correctness of the persistent storage of state data.
[0081] This embodiment constructs a version-based state data cache and asynchronous persistent storage mechanism. After the consensus of the new block is passed, the block data is persistently stored and the state data is written to the cache first, and then the consensus or block execution of the next block can be started. The state data in the cache is asynchronously persistently stored, and when the state data needs to be read and written during this process, a data copy is built based on the latest version of the state data in the cache and persistent storage, and then read and write, thereby reducing the new block processing blockade caused by persistent storage of state data, improving the blockchain transaction throughput while avoiding inconsistent or incorrect blockchain state execution results.
[0082] Embodiment 2
[0083] A system for asynchronous storage of state data includes at least one blockchain node, wherein the blockchain node includes:
[0084] The block processing module is configured to construct, execute and verify the consensus of blocks based on the blockchain communication rules and consensus rules, and to store the block data that has passed the consensus persistently;
[0085] The state data cache module is configured to write the state data into the cache first after the consensus of the new block is passed, cache the block state data set to be persisted with the block height as the version, and asynchronously store the cached state data of each version persistently; when receiving a request to read or write state data, it builds a data copy based on the latest version of the state data in the cache and persistent storage, and then reads and writes.
[0086] In some embodiments, the blockchain node further includes a state execution engine module, and the state execution engine module includes:
[0087] The state data execution module is configured to form a state data set with all write data related to changes, additions or deletions of the state data before writing the state data into the cache;
[0088] A Bloom filter construction module, configured to construct a Bloom filter based on the identifier of the state data;
[0089] The state root calculation module is configured to calculate the state root of the block based on the write data collected by the state data execution module, and submit it for block verification.
[0090] In some embodiments, the state data cache module includes:
[0091] The state data cache queue is configured to use a queue structure with a first-in-first-out cache state execution engine module to cache the state data set of each block version to be persisted;
[0092] The state data asynchronous storage module is configured to sequentially obtain a version of the state data set to be persisted from the state data cache queue and store it persistently. After completing the persistent storage of a version of the state data set, the state data set is deleted from the state data cache queue, the Bloom filter of the version data is deleted from the latest version state data acquisition module, and the block height of the currently completed state data persistent storage in the persistent storage is updated;
[0093] The latest version status data acquisition module is configured to retrieve the latest version of the status data required for block status execution based on the Bloom filter of each version of the status data to be persisted, and create a data copy based on the retrieved data.
[0094] Of course, the protected subject of the second embodiment may also be a blockchain node directly.
[0095] Embodiment 3
[0096] A node crash recovery method for asynchronous storage of state data, such as Figure 4 As shown, based on the above embodiment, the following steps are included:
[0097] Step 201: Obtain the current block height currentBH of the node and the block height stateBH of the current completed state data persistent storage of the node from the persistent storage.
[0098] Step 202: Compare whether stateBH is less than currentBH. If so, proceed to step 203; otherwise, it means that all cached state data has been persistently stored when the node is down, and there is no need to restore the incompletely persisted cached data.
[0099] Step 203: Get the block from the persistent storage stateBH+1 Block data, block stateBH+1 The transaction in is replayed and the state root is calculated based on the state data obtained by the execution.
[0100] Step 204: Compare the state root obtained in step 3 with the block block stateBH+1 If so, proceed to step 205; otherwise, proceed to step 206.
[0101] Step 205: Store the state data in persistent storage and update stateBH to stateBH+1. Repeat steps 202 to 206 until the block is reached. currentBH , realize the re-execution and persistent storage of state data, complete the recovery of state data, restart the node, and continue to participate in subsequent blockchain system work.
[0102] Step 206: Abandon this block and subsequent blocks with higher block heights, request synchronization of missing block data from other nodes in the network, recheck and execute until the block height is equalized.
[0103] This embodiment can prevent some data in the state cache queue from being lost due to incomplete persistent storage after an unexpected crash of a blockchain node.
[0104] This embodiment stores the state data blocks that the blockchain node has currently completed persistent storage in real time, so that after the node abnormally crashes and restarts, the cached state data that failed to complete persistent storage when the node crashed can be restored based on the block data persistently stored in the node, and the missing state data can be persistently stored, avoiding the loss of state data after the node abnormally crashes due to the state data caching mechanism.
[0105] Embodiment 4
[0106] A blockchain node that stores state data asynchronously, such as Figure 5 As shown, it specifically includes a block processing module 301, a state execution engine 302, a state data cache module 303, a state data recovery module 304 and a block synchronization module 305.
[0107] In this embodiment, the block processing module 301 constructs, executes and verifies the consensus of blocks based on the blockchain communication rules and consensus rules, and persistently stores the block data that has passed the consensus.
[0108] In this embodiment, the state execution engine 302 provides reading and writing of block state data, aggregation of write data, construction of Bloom filters for write data, and calculation of new block state roots when a new block is executed.
[0109] It specifically includes a state data execution module 3021 , a Bloom filter construction module 3022 , and a state root calculation module 3023 .
[0110] The state data execution module 3021 provides state execution when a new block is executed, and collects write operation data involved in changes, additions or deletions during state execution.
[0111] The Bloom filter construction module 3022 constructs a Bloom filter using write operation data identifiers that are changed, added, or deleted during state execution, and submits the state data Bloom filter of the block to the latest version state data acquisition module 3033 after the block reaches the on-chain state.
[0112] After the execution of the block and state is completed, the state root calculation module 3023 calculates the state root of the block based on the write data collected by the state data execution module, and submits it to the block processing module 301 for block verification.
[0113] In this embodiment, the state data cache module 303 caches the block state data set to be persisted with the block height as the version, and retrieves the latest state data version in the cache and persistent storage when processing a new block and submits it to the state data execution module for state execution, asynchronously persisting the cached state data of each version.
[0114] Specifically, it includes a state data cache queue 3031 , a state data asynchronous storage module 3032 , and a latest version state data acquisition module 3033 .
[0115] In some embodiments, the state data cache queue 3031 adopts a queue structure with a first-in-first-out cache state data set to be persisted for each block version collected by the state execution engine 302 .
[0116] The state data asynchronous storage module 3032 sequentially obtains a version of the state data set to be persisted from the state data cache queue 3031 and stores it persistently. After completing the persistent storage of a version of the state data set, the state data set is deleted from the state data cache queue 3031, the Bloom filter of the version data is deleted from the latest version state data acquisition module 3033, and the block height of the currently completed state data persistent storage in the persistent storage is updated.
[0117] The latest version status data acquisition module 3033 retrieves the latest version of the status data required for block status execution based on the Bloom filter of each version of the status data to be persisted, and creates a data copy based on the retrieved data and submits it to the status data execution module 3021.
[0118] In this embodiment, the state data recovery module 304 checks whether there is a version missing in the persistent state data of the node based on the current block height of the persistently stored node and the block height of the current completed state data persistence when the node is started. If there is, the block data is replayed starting from the block height of the smallest version of the missing state data, and the state root is calculated based on the executed state data to check whether it is equal to the state root in the block data. If it is equal, the state data set is persistently stored until it reaches the current block height.
[0119] That is, the state data recovery module 304 also includes:
[0120] The missing judgment module 3041 is configured to check whether the persistent state data of the node is missing based on the current block height of the persistently stored node and the block height of the currently completed state data persistence;
[0121] The replay execution module 3042 is configured to replay and execute the block data starting from the block height of the minimum version of the missing state data, and calculate the state root based on the executed state data to verify whether it is equal to the state root in the block data. If equal, the state data set is persistently stored until the current block height is reached.
[0122] In this embodiment, if the state root obtained after the block data replay is not equal to the block data, the block and subsequent block data are discarded, and the block synchronization module synchronizes the missing blocks from other nodes of the blockchain.
[0123] The block synchronization module 305 synchronizes the missing blocks from other nodes of the blockchain, and executes, verifies and stores them on the chain until the current block height in the blockchain system is reached.
[0124] Embodiment 5
[0125] A node crash recovery system for asynchronously storing state data includes at least one blockchain node provided in Embodiment 2 or a blockchain node provided in Embodiment 4.
[0126] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented 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.
[0127] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0128] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0129] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, the present invention may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made by those skilled in the art within the spirit and principle of the present invention without creative labor shall be included in the protection scope of the present invention.
Claims
1. A method for asynchronous storage of state data, characterized in that: Including the following steps: After the new block is consensus passed, the block data is persistently stored, and the state data is first written into the cache, and the state data in the cache is asynchronously persistently stored; During the above process, when a read / write request for state data is received, a data copy is constructed based on the latest version of the state data in the cache and the persistent storage, and then read / write is performed.
2. A method for asynchronous storage of state data as claimed in claim 1, characterized in that: Before writing the state data into the cache, all write data involving changes, additions, or deletions of the state data are formed into a state data set. Based on the identifier of the state data, a Bloom filter is constructed, and the state data set is batch-written into the state cache queue with the block height n of this block as the version, and the Bloom filter corresponding to the state data set of this version is written into the Bloom filter cache.
3. A method for asynchronous storage of state data as claimed in claim 1, characterized in that: The process of persistently storing the block data is to determine that the current block is consensus passed according to the consensus rules. After reaching the persistent chain-up state, the block data and the current block height are persistently stored.
4. A method for asynchronous storage of state data as claimed in claim 1, characterized in that: The process of asynchronously persistently storing the state data in the cache includes: for each version of the state data set in the state cache queue, asynchronously, starting from the lowest version to the highest version according to the version number, the persistent storage is performed in turn. After each version of the state data set is persistently stored, the cached state data set of this version is deleted from the state cache queue, the Bloom filter of this version is deleted from the Bloom filter cache, the block height of the currently completed persistent storage of the state data in the persistent storage is updated, and the persistent storage of the next version of the state data set is started until there is no data to be persistently stored in the state cache queue.
5. A method for asynchronous storage of state data according to any one of claims 1 to 4, characterized in that: Write the state data of the block data into the state cache queue, and the construction, consensus, or block execution of the next block can be started without waiting for the data in the state cache queue to be persistently stored; Or further, if the construction, consensus, or execution process of the new block needs to read / write state data, then retrieve from the Bloom filters of each version of the state data set in the cache in turn from the highest version to the lowest version until the highest version state data set cache where the required data may exist is located, and obtain the data from it; If the required data does not exist in any version of the cached state data, then the latest version of the required data is in the persistent storage, and the required data is obtained from the persistent state data.
6. A node crash recovery method for asynchronous storage of state data, based on the method for asynchronous storage of state data according to any one of claims 1 to 5, characterized in that: When the node crashes and restarts, the cached state data that was not completed in persistent storage when the node crashed is restored based on the block data persistently stored by the node, and the missing state data is persistently stored.
7. A node crash recovery method for asynchronous storage of state data as claimed in claim 6, characterized in that: The process of restoring the cached state data that was not completed in persistent storage when the node crashed based on the block data persistently stored by the node includes: obtaining the current block height a of this node and the block height b of the currently completed persistent storage of the state data of this node from the persistent storage. If b < a, it means that there is uncompleted persistent storage of state data when this node crashed; The node obtains the next block of the persistent storage of the node's current completed state data, replays and executes the transactions in the next block, calculates the state root based on the state data obtained by execution, and compares it with the state root recorded in the next block. If they are equal, it means that the state execution is correct, and the state data is stored in the persistent storage; Follow the above steps to complete the re-execution and persistent storage of the state data of the remaining blocks in turn to achieve the recovery of the state data; Or, if the state root obtained during the state data recovery process is inconsistent with the state root recorded in the block data, the block and subsequent blocks with higher blocks are discarded, and the missing block data is requested to be synchronized from other nodes in the network, and re-checked and executed until the block height is equal.
8. A system for asynchronous storage of state data, characterized in that: The method comprises at least one blockchain node, wherein the blockchain node comprises: The block processing module is configured to construct, execute and verify the consensus of blocks based on the blockchain communication rules and consensus rules, and to store the block data that has passed the consensus persistently; The state data cache module is configured to write the state data into the cache first after the consensus of the new block is passed, cache the block state data set to be persisted with the block height as the version, and asynchronously store the cached state data of each version persistently; when receiving a request to read or write state data, it builds a data copy based on the latest version of the state data in the cache and persistent storage, and then reads and writes.
9. A system for asynchronous storage of state data as claimed in claim 8, characterized in that: The blockchain node also includes a state execution engine module, and the state execution engine module includes: The state data execution module is configured to form a state data set with all write data related to changes, additions or deletions of the state data before writing the state data into the cache; A Bloom filter construction module, configured to construct a Bloom filter based on the identifier of the state data; A state root calculation module is configured to calculate the state root of the block based on the write data collected by the state data execution module, and submit it to the block processing module for block verification; Or, the state data cache module includes: The state data cache queue is configured to use a queue structure with a first-in-first-out cache state execution engine module to cache the state data set of each block version to be persisted; The state data asynchronous storage module is configured to sequentially obtain a version of the state data set to be persisted from the state data cache queue and store it persistently. After completing the persistent storage of a version of the state data set, the state data set is deleted from the state data cache queue, the Bloom filter of the version data is deleted from the latest version state data acquisition module, and the block height of the currently completed state data persistent storage in the persistent storage is updated; The latest version status data acquisition module is configured to retrieve the latest version of the status data required for block status execution based on the Bloom filter of each version of the status data to be persisted, and create a data copy based on the retrieved data.
10. A node crash recovery system for asynchronous storage of state data, based on the system described in any one of claims 8 or 9, comprising at least one blockchain node, characterized in that: The blockchain node includes: The state data recovery module is configured to recover the cached state data that failed to complete persistent storage when the node crashed based on the block data persistently stored in the node when the node crashed and restarted, and complete persistent storage of the missing state data; include: The missing judgment module is configured to check whether the persistent state data of the node is missing based on the current block height of the persistently stored node and the block height of the currently completed state data persistence; The replay execution module is configured to replay and execute the block data starting from the block height of the minimum version of the missing state data, and calculate the state root based on the executed state data to verify whether it is equal to the state root in the block data. If equal, the state data set is persistently stored until the current block height is reached; Or further, the system also includes a block synchronization module, which is configured to synchronize missing blocks from other nodes of the blockchain, and execute, verify and store them on the chain until the current block height in the blockchain system is reached.
Citation Information
Patent Citations
A block chain state data storage and reading method based on multi-level caching
CN109684337A
Asynchronous account settling method and device of blockchain, medium and electronic equipment
CN112291372A
Method and apparatus for writing into state database, electronic device, and storage medium
WO2021139109A1
