Blockchain-based state data processing method, device, and storage medium
By retaining the historical version of the state data in the state database of the blockchain node and adding it to the queue, the problem of low read and write efficiency is solved, the parallel execution of read and write operations is achieved, and the state data processing efficiency of the blockchain is improved.
Patent Information
- Application Number
- CN202210648649.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-06-09
- Publication Date
- 2025-09-09
- Estimated Expiration
- 2042-06-09
AI Technical Summary
In the existing technology, the reading and writing efficiency of blockchain status data is low. Especially when a large number of transactions are executed concurrently, the lock synchronization technology makes it impossible to execute read and write operations in parallel, reducing efficiency.
By retaining the historical version of the state data in the state database of the blockchain node and adding the state data to be written to the queue, the block number is stored in the queue as a snapshot. When reading the task, it is determined whether the target block number exists in the queue, and the corresponding state data is read from the database, avoiding long-term locking.
Improves the reading and writing efficiency of blockchain status data, ensures that read operations do not affect write operations, and improves the efficiency of concurrent reading and writing.
Smart Images

Figure CN115048457B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of blockchain technology, and more specifically, to a method, device, and storage medium for processing state data based on blockchain. Background Art
[0002] When a blockchain creates or modifies a block, it triggers an update to its state data. In related technologies, when state data is updated, only the latest version of the state data is recorded in the blockchain state database. In other words, each time a blockchain node executes a block to update the state data in the state database, the latest version of the state data overwrites the previous version of the state data.
[0003] After the state data is recorded in the state database of the blockchain, the state data can be read and written from the state database. Since the operation of writing state data will change the state data, if the state data is read or written at the same time, the read state data will be inconsistent with the state data currently stored in the state database. In order to solve this problem, lock synchronization technology has emerged in related technologies. That is, to ensure that the read state data is consistent when each transaction simulation of the blockchain is executed, the blockchain node will add a read lock to the state database after obtaining the transaction simulator; at the same time, when the blockchain node executes the block to write the state data, it will add a write lock to the state database.
[0004] However, lock synchronization technology causes the state database to be locked for a long time, making it impossible to read and submit state data in parallel, reducing the read and write efficiency of the blockchain's state data. When a large number of transactions are executed concurrently, the decline in the read and write efficiency of the state data is particularly obvious.
[0005] Currently, no effective solution has been proposed to the problem of low efficiency in reading and writing status data in related technologies. Summary of the Invention
[0006] The present application provides a blockchain-based state data processing method, device, and storage medium to solve the problem of low state data reading and writing efficiency in related technologies.
[0007] According to one aspect of the present application, a method for processing state data based on a blockchain is provided. The method includes: obtaining a data processing task through a target node in the blockchain; when the data processing task is a state data write task, storing the state data to be written in the state database of the target node, and adding the block number corresponding to the state data to be written to the first queue of the target node, wherein the block number is the number corresponding to the block that triggers the update of the state data; when the data processing task is a state data read task, determining the block number corresponding to the state data of the current version of the blockchain, obtaining the target block number, and determining whether the target block number exists in the first queue of the target node; if the target block number exists in the first queue, reading the state data corresponding to the target block number from the state database of the target node.
[0008] Optionally, adding the block number corresponding to the status data to be written to the first queue of the target node includes: determining the initial reference count of the block number corresponding to the status data to be written, wherein the initial reference count is used to indicate that the status data corresponding to the block number has not been referenced by the status data reading task; combining the initial reference count and the block number into a snapshot, and storing the snapshot at the end of the first queue.
[0009] Optionally, after determining whether the target block number exists in the first queue of the target node, the method further includes: if the target block number does not exist in the first queue, determining the initial number of references of the target block number, wherein the initial number of references is used to indicate that the status data corresponding to the target block number has not been referenced by the status data reading task; combining the number of references and the target block number into a snapshot, and storing the snapshot at the end of the first queue.
[0010] Optionally, before reading the status data corresponding to the target block number from the status database of the target node, the method further includes: adjusting the initial reference count in the snapshot where the target block number is located to obtain a first reference count, wherein the first reference count is used to indicate that the status data corresponding to the snapshot is referenced by the status data reading task; after reading the status data corresponding to the target block number from the status database of the target node, the method further includes: adjusting the first reference count to obtain a second reference count, wherein the second reference count is used to indicate that the status data corresponding to the snapshot has been referenced by the status data reading task.
[0011] Optionally, after adjusting the first reference count to obtain the second reference count, the method further includes: determining whether the second reference count of the snapshot is equal to the initial reference count; and if the second reference count is equal to the initial reference count, moving the snapshot from the first queue to the second queue.
[0012] Optionally, after moving the snapshot from the first queue to the second queue, the method further includes: determining the block number of the snapshot in the second queue to obtain the failed block number; deleting the snapshot in the second queue, and deleting the status data corresponding to the failed block number from the status database.
[0013] Optionally, the status data reading task is triggered by a transaction task. After reading the status data corresponding to the target block number from the status database of the target node, the method further includes: executing the transaction task according to the status data corresponding to the target block number to obtain an execution result; and creating a status data writing task according to the execution result.
[0014] According to another aspect of the present application, a state data processing device based on a blockchain is provided. The device includes: an acquisition unit for acquiring a data processing task through a target node in the blockchain; a first data processing unit for storing the state data to be written in a state database of the target node when the data processing task is a state data write task, and adding the block number corresponding to the state data to be written to a first queue of the target node, wherein the block number is the number corresponding to the block that triggers the update of the state data; a second data processing unit for determining the block number corresponding to the state data of the current version of the blockchain when the data processing task is a state data read task, obtaining a target block number, and determining whether the target block number exists in the first queue of the target node; and a reading unit for reading the state data corresponding to the target block number from the state database of the target node if the target block number exists in the first queue.
[0015] According to another aspect of an embodiment of the present invention, a computer storage medium is further provided, which is used to store a program, wherein when the program is running, the device where the computer storage medium is located is controlled to execute a method for processing state data based on blockchain.
[0016] According to another aspect of an embodiment of the present invention, an electronic device is 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 when the computer-readable instructions are executed, a method for processing state data based on blockchain is executed.
[0017] Through this application, the following steps are adopted: obtaining a data processing task through the target node in the blockchain; when the data processing task is a state data writing task, storing the state data to be written in the state database of the target node, and adding the block number corresponding to the state data to be written to the first queue of the target node, wherein the block number is the number corresponding to the block that triggers the update of the state data; when the data processing task is a state data reading task, determining the block number corresponding to the state data of the current version of the blockchain, obtaining the target block number, and judging whether the target block number exists in the first queue of the target node; when the target block number exists in the first queue, reading the state data corresponding to the target block number from the state database of the target node solves the problem of low state data reading and writing efficiency in the related art. By retaining the historical version of the state data, when the blockchain performs state data reading and writing operations at the same time, reading the state data of the corresponding version does not affect the writing of the state data, thereby achieving the effect of improving the read and write efficiency of the state data. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] The accompanying drawings, which constitute part of this application, are intended to provide a further understanding of this application. The exemplary embodiments and descriptions of this application are intended to explain this application and do not constitute an improper limitation on this application. In the accompanying drawings:
[0019] Figure 1 This is the process of the blockchain-based state data processing method provided in the embodiment of the present application Figure 1 ;
[0020] Figure 2 This is the process of the blockchain-based state data processing method provided in the embodiment of the present application Figure 2 ;
[0021] Figure 3 2 is a schematic diagram of a blockchain-based state data processing device according to an embodiment of the present application;
[0022] Figure 4 This is a schematic diagram of an electronic device provided according to an embodiment of the present application. DETAILED DESCRIPTION
[0023] It should be noted that, in the absence of conflict, the embodiments and features of the embodiments in this application can be combined with each other. The present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.
[0024] In order to enable those skilled in the art to better understand the present invention, the following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments in the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts should fall within the scope of protection of this application.
[0025] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequential order. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present application described here. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0026] 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 for analysis, etc.) involved in this disclosure are all information and data authorized by the user or fully authorized by all parties.
[0027] For ease of description, some nouns or terms involved in the embodiments of the present application are explained below:
[0028] Transaction Simulation: During the blockchain endorsement phase, peer nodes simulate transaction execution. This requires obtaining a transaction simulator. While simulating transactions, the simulator does not actually write the transaction results to the state database. Instead, it stores the results of transaction queries, additions, and deletions in a read-write set. The read-write set is submitted to the state database only when the peer node executes the block.
[0029] According to an embodiment of the present application, a method for processing state data based on blockchain is provided.
[0030] Figure 1 This is the process of the method for processing state data based on blockchain according to the embodiment of the present application Figure 1 .like Figure 1 As shown, the method includes the following steps:
[0031] Step S102: Obtain data processing tasks through the target node in the blockchain.
[0032] Specifically, the target node is the Peer node on the blockchain, and the data processing tasks include status data writing tasks and status data reading tasks.
[0033] Step S104, when the data processing task is a status data writing task, the status data to be written is stored in the status database of the target node, and the block number corresponding to the status data to be written is added to the first queue of the target node, wherein the block number is the number corresponding to the block that triggers the update of the status data.
[0034] Specifically, the data writing task is the task of updating the status data of the Peer node when executing a block. The status data to be written refers to the latest version of the status data obtained from the executed block. The status database is a database that stores the status data of the target node. The block number corresponding to the status data to be written is the block number of the executed block. The first queue is the snapshot queue stored on the target node. When the status data to be written is stored in the status database, the block number corresponding to the status data to be written is added to the first queue. This can facilitate the subsequent acquisition of the block number from the first queue, thereby indexing the corresponding status data from the status database.
[0035] For example, Table 1 is the specific situation of the state data stored in the state database of the target node. As shown in Table 1, Key is the primary key of the state data in the state database. The state data in Table 1 are all state data with the primary key of 1. When the block number of the executed block is 1, the corresponding state data value is 1, when the block number of the executed block is 2, the corresponding state data value is 10, and when the block number of the executed block is 3, the corresponding state data value is 100. When new state data is added to the state database, the new data is no longer used to overwrite the old data, but the latest version of the state data is written to the database.
[0036] Table 1
[0037]
[0038] Step S106, when the data processing task is a status data reading task, determine the block number corresponding to the status data of the current version of the blockchain, obtain the target block number, and determine whether the target block number exists in the first queue of the target node.
[0039] Specifically, the status data reading task is to read the status data in the status database on the Peer node when the Peer node performs transaction simulation execution during the blockchain endorsement phase. The target block number is the latest version of the status data in the Peer node's status database, that is, the status data with the largest block number.
[0040] Step S108 : When the target block number exists in the first queue, the status data corresponding to the target block number is read from the status database of the target node.
[0041] Specifically, when the status data corresponding to the target block number has been stored in the status database, the target block number may not have been added to the first queue. Therefore, before reading the status data, it is necessary to first determine whether the target block number exists in the first queue. When the target block number is read, the corresponding status data is obtained. Compared with directly querying the status data from the status database, the efficiency of obtaining the status data is improved.
[0042] The state data processing method based on blockchain provided by the embodiment of the present application obtains a data processing task through the target node in the blockchain; when the data processing task is a state data writing task, the state data to be written is stored in the state database of the target node, and the block number corresponding to the state data to be written is added to the first queue of the target node, wherein the block number is the number corresponding to the block that triggers the update of the state data; when the data processing task is a state data reading task, the block number corresponding to the state data of the current version of the blockchain is determined, the target block number is obtained, and it is judged whether the target block number exists in the first queue of the target node; when the target block number exists in the first queue, the state data corresponding to the target block number is read from the state database of the target node, solving the problem of low read and write efficiency of state data in the related art. By retaining the historical version of the state data, when the blockchain performs read and write operations on the state data at the same time, the state data of the corresponding version is read without affecting the writing of the state data, thereby achieving the effect of improving the read and write efficiency of the state data.
[0043] In order to store different versions of state data into the state database, optionally, in the blockchain-based state data processing method provided in an embodiment of the present application, adding the block number corresponding to the state data to be written to the first queue of the target node includes: determining the initial number of references of the block number corresponding to the state data to be written, wherein the initial number of references is used to indicate that the state data corresponding to the block number has not been referenced by the state data reading task; combining the initial number of references and the block number into a snapshot, and storing the snapshot at the end of the first queue.
[0044] Specifically, the initial reference count is 0, indicating that the state data to be written has not yet been read during the transaction simulation. When each version of the state data is written to the state database, a snapshot is stored in the first queue on the peer node. The element data structure of the snapshot is defined as: block number (numeric type) and reference count (numeric type). Each snapshot is stored at the end of the first queue when it is created. By creating a snapshot, the storage location of each version of the state data is recorded, allowing for quick location of the required version of the state data when reading the state data, improving read efficiency.
[0045] When reading status data, there is a situation where the snapshot corresponding to the read status data has not been created. Optionally, in the blockchain-based status data processing method provided in an embodiment of the present application, after determining whether the target block number exists in the first queue of the target node, the method also includes: when the target block number does not exist in the first queue, determining the initial number of references of the target block number, wherein the initial number of references is used to indicate that the status data corresponding to the target block number has not been referenced by the status data reading task; combining the number of references and the target block number into a snapshot, and storing the snapshot at the end of the first queue.
[0046] Specifically, when reading state data, a snapshot for the target block number may not yet be created. In this case, a snapshot corresponding to the target block number needs to be created. By creating a new block number for the target block number for which a snapshot has not yet been created, the state data corresponding to the target block number can be quickly located the next time the state data is read, thereby improving the efficiency of reading state data.
[0047] The number of references in a snapshot is used to indicate the situation in which the snapshot is referenced. Optionally, in the blockchain-based state data processing method provided in an embodiment of the present application, before reading the state data corresponding to the target block number from the state database of the target node, the method further includes: adjusting the initial number of references in the snapshot where the target block number is located to obtain a first number of references, wherein the first number of references is used to indicate that the state data corresponding to the snapshot is referenced by the state data reading task; after reading the state data corresponding to the target block number from the state database of the target node, the method further includes: adjusting the first number of references to obtain a second number of references, wherein the second number of references is used to indicate that the state data corresponding to the snapshot has been referenced by the state data reading task.
[0048] Specifically, the first reference count is the number of references after adjusting the initial reference count of 0 for the snapshot. Each time a transaction calls the snapshot, the reference count for the snapshot increases. The second reference count is the number of references after adjusting the first reference count for the snapshot. Each time a transaction that calls the snapshot is completed, the reference count for the snapshot decreases. By adjusting the reference count to indicate the state data corresponding to the snapshot is being called, invalid state data can be obtained in a timely manner and cleared to reduce memory pressure on the state database.
[0049] For example, if the state data type corresponding to snapshot A is 1, the state data is 10, and the block number is 2, the initial reference count of snapshot A is 0 when it is created. When the peer node simulates the execution of transaction X, the state data corresponding to snapshot A is called. At this time, the first reference count of snapshot A is 1. After the simulation of transaction X is completed, the second reference count of snapshot A is 0.
[0050] Since the storage capacity of the state database is limited, it is necessary to regularly clean up the state data in the state database. Optionally, in the blockchain-based state data processing method provided in the embodiment of the present application, after adjusting the first reference count to obtain the second reference count, the method further includes: determining whether the second reference count of the snapshot is equal to the initial reference count; and if the second reference count is equal to the initial reference count, moving the snapshot from the first queue to the second queue.
[0051] Specifically, the snapshot's reference count is determined to be zero after the transaction simulation completes. If so, the state data corresponding to the snapshot will no longer be used and is considered invalid. Therefore, the snapshot is moved to the second queue, the snapshot pending destruction queue, which marks state data ready for cleanup. By moving invalid state data to the snapshot pending destruction queue, marking it ready for cleanup, we can conserve storage space in the state data database.
[0052] After obtaining the second queue, the corresponding status data in the second queue can be cleared. Optionally, in the blockchain-based status data processing method provided in the embodiment of the present application, after moving the snapshot from the first queue to the second queue, the method also includes: determining the block number of the snapshot in the second queue to obtain the invalid block number; deleting the snapshot in the second queue, and deleting the status data corresponding to the invalid block number from the status database.
[0053] Specifically, the block number of the snapshot in the snapshot queue is the invalid block number. The state data corresponding to the invalid block number will not be read. Therefore, the state data corresponding to the invalid block number is deleted from the state database, and the snapshot in the snapshot queue is also deleted. By deleting the snapshots in the snapshot queue and the state data corresponding to the invalid block number, the state database is cleaned up, thereby saving storage space in the state database.
[0054] After reading the status data, a new status data writing task may be created. Optionally, in the blockchain-based status data processing method provided in an embodiment of the present application, the status data reading task is triggered by a transaction task. After reading the status data corresponding to the target block number from the status database of the target node, the method further includes: executing the transaction task based on the status data corresponding to the target block number to obtain an execution result; and creating a status data writing task based on the execution result.
[0055] Specifically, after reading the state data, the transaction task is executed based on the state data, and the execution result is obtained and stored in the peer node cache. When the execution result is reached consensus on each node of the blockchain, a new state data write task is created based on the execution result in the cache. This new state data write task completes the state data version update.
[0056] According to another embodiment of the present application, a method for processing blockchain-based status data is provided.
[0057] Figure 2 This is the process of the method for processing state data based on blockchain according to the embodiment of the present application Figure 2 .like Figure 2 As shown, the method includes the following steps:
[0058] Step S201: When the transaction simulation starts, the current block number (recorded as H) is obtained, the block number H is recorded in the block number snapshot queue, and the snapshot object corresponding to the block number H is recorded using a pointer. At the same time, the reference count of the snapshot corresponding to the block number H is 1.
[0059] In step S202, during the transaction simulation execution, state data is obtained and the GetState(key, version) method is used to query the value of the state data of the specified version, where the value of version is block number H. The GetState(key, version) method queries the state database for the state data with the largest block number among the state data with a block number less than or equal to version.
[0060] Step S203: When the transaction simulation ends, the reference count of the snapshot object of the block number pointed to by the transaction is reduced by 1. If the reference count is not 0, the process is discontinued; if the reference count is 0, the block number is added to the end of the queue of block numbers to be destroyed.
[0061] Step S204: Record the historical version of the state data into the state database, where the version is the block number of the updated state data.
[0062] Step S205: Establish a cleanup thread for state data versions that have no references. Periodically retrieve the block number to be destroyed from the block number to be destroyed queue. If the state data has only one version, exit the deletion process. If the state data has multiple versions, if a version greater than the block number to be destroyed exists in the state data version, delete all state data in the state database whose version is less than or equal to the block number to be destroyed. If a version greater than the block number to be destroyed does not exist in the state data version, delete all state data in the state database whose version is less than the block number to be destroyed.
[0063] This application proposes a method for processing blockchain-based state data. Compared with the existing method of concurrently reading and writing state data by locking and synchronizing state data, this application can eliminate the long-term locking when reading and writing state data, thereby improving the concurrent reading and writing efficiency of blockchain state data.
[0064] It should be noted that the steps shown in the flowcharts of the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and that, although a logical order is shown in the flowcharts, in some cases, the steps shown or described can be executed in an order different from that shown here.
[0065] The present application also provides a blockchain-based state data processing device. It should be noted that the blockchain-based state data processing device of the present application can be used to execute the blockchain-based state data processing method provided in the present application. The following describes the blockchain-based state data processing device provided in the present application.
[0066] Figure 3 Schematic diagram of a device for processing state data based on blockchain according to an embodiment of the present application. Figure 3 As shown, the device includes:
[0067] An acquisition unit 301 is configured to acquire a data processing task through a target node in the blockchain;
[0068] The first data processing unit 302 is configured to, when the data processing task is a status data writing task, store the status data to be written in the status database of the target node, and add the block number corresponding to the status data to be written to the first queue of the target node, where the block number is the number corresponding to the block that triggers the update of the status data;
[0069] The second data processing unit 303 is configured to, when the data processing task is a state data reading task, determine the block number corresponding to the state data of the current version of the blockchain, obtain a target block number, and determine whether the target block number exists in the first queue of the target node;
[0070] The reading unit 304 is configured to read the status data corresponding to the target block number from the status database of the target node when the target block number exists in the first queue.
[0071] The blockchain-based state data processing device provided by the embodiment of the present application obtains a data processing task through a target node in the blockchain through an acquisition unit 301; the first data processing unit 302, when the data processing task is a state data write task, stores the state data to be written in the state database of the target node, and adds the block number corresponding to the state data to be written to the first queue of the target node, wherein the block number is the number corresponding to the block that triggers the update of the state data; the second data processing unit 303, when the data processing task is a state data read task, determines the block number corresponding to the state data of the current version of the blockchain, obtains the target block number, and determines whether the target block number exists in the first queue of the target node; the reading unit 304, when the target block number exists in the first queue, reads the state data corresponding to the target block number from the state database of the target node, thereby solving the problem of low state data reading and writing efficiency in the related art. By retaining the historical version of the state data, when the blockchain simultaneously performs state data reading and writing operations, the corresponding version of the state data is read without affecting the writing of the state data, thereby achieving the effect of improving the state data reading and writing efficiency.
[0072] Optionally, in the blockchain-based state data processing device provided in an embodiment of the present application, the first data processing unit 302 includes: a first determination module, used to determine the initial reference count of the block number corresponding to the state data to be written, wherein the initial reference count is used to indicate that the state data corresponding to the block number has not been referenced by the state data reading task; a first storage module, used to combine the initial reference count and the block number into a snapshot, and store the snapshot at the end of the first queue.
[0073] Optionally, in the blockchain-based state data processing device provided in an embodiment of the present application, the second data processing unit 303 includes: a second determination module, used to determine the initial number of references of the target block number when the target block number does not exist in the first queue, wherein the initial number of references is used to indicate that the state data corresponding to the target block number has not been referenced by the state data reading task; a second storage module, used to combine the number of references and the target block number into a snapshot, and store the snapshot at the end of the first queue.
[0074] Optionally, in the blockchain-based state data processing device provided in an embodiment of the present application, the device further includes: a first adjustment unit, configured to adjust the initial number of references in the snapshot where the target block number is located to obtain a first number of references, wherein the first number of references is used to indicate that the state data corresponding to the snapshot is referenced by the state data reading task; the device further includes: a second adjustment unit, configured to adjust the first number of references to obtain a second number of references, wherein the second number of references is used to indicate that the state data corresponding to the snapshot has been referenced by the state data reading task.
[0075] Optionally, in the blockchain-based state data processing device provided in an embodiment of the present application, the device further includes: a judgment unit, used to judge whether the second number of references of the snapshot is equal to the initial number of references; and a moving unit, used to move the snapshot from the first queue to the second queue when the second number of references is equal to the initial number of references.
[0076] Optionally, in the blockchain-based state data processing device provided in an embodiment of the present application, the device further includes: an invalid block determination unit, used to determine the block number of the snapshot in the second queue to obtain the invalid block number; and a deletion unit, used to delete the snapshot in the second queue and delete the state data corresponding to the invalid block number from the state database.
[0077] Optionally, in the blockchain-based status data processing device provided in an embodiment of the present application, the device also includes: an acquisition unit, used to execute a transaction task based on the status data corresponding to the target block number and obtain an execution result; and a creation unit, used to create a status data writing task based on the execution result.
[0078] The above-mentioned blockchain-based state data processing device includes a processor and a memory. The above-mentioned acquisition unit 301, the first data processing unit 302, the second data processing unit 303 and the reading unit 304 are all stored in the memory as program units, and the processor executes the above-mentioned program units stored in the memory to realize corresponding functions.
[0079] The processor contains a kernel, which retrieves the corresponding program unit from the memory. One or more kernels can be set, and the efficiency of reading and writing state data can be improved by adjusting kernel parameters.
[0080] The memory may include non-permanent memory in a computer-readable medium, 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.
[0081] An embodiment of the present application also provides a computer storage medium, which is used to store a program, wherein when the program is running, the device where the computer storage medium is located is controlled to execute a method for processing state data based on blockchain.
[0082] like Figure 4 As shown, an embodiment of the present application further provides an electronic device. The electronic device 401 includes a processor, a memory, and a program stored in the memory and executable on the processor. When the processor executes the program, the following steps are performed: processing of blockchain-based state data. The device herein may be a server, a PC, a PAD, a mobile phone, etc.
[0083] Those skilled in the art will appreciate that the embodiments of the present application can be provided as methods, systems, or computer program products. Therefore, the present application can adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application can adopt the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to magnetic disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.
[0084] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes 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 steps in the process. 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.
[0085] These computer program instructions may also be stored in a computer readable memory that can direct a computer or other programmable data processing device to work 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 1 a process or multiple processes and / or boxes Figure 1 The function specified in one or more boxes.
[0086] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operational steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing the instructions executed on the computer or other programmable device for implementing the process. Figure 1 a process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0087] In a typical configuration, a computing device includes one or more processors (CPUs), input / output interfaces, network interfaces, and memory.
[0088] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0089] Computer-readable media includes permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. The information can be computer-readable instructions, data structures, program modules 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 technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include transitory computer-readable media (transitory media), such as modulated data signals and carrier waves.
[0090] It should also be noted that the terms "comprises," "includes," or any other variations thereof are intended to encompass non-exclusive inclusion, such that a process, method, commodity, or apparatus that includes a series of elements includes not only those elements but also other elements not explicitly listed, or includes elements inherent to such process, method, commodity, or apparatus. In the absence of further limitations, an element defined by the phrase "comprises a ..." does not exclude the presence of other identical elements in the process, method, commodity, or apparatus that includes the element.
[0091] The above are merely embodiments of the present application and are not intended to limit the present application. For those skilled in the art, the present application may have various changes and variations. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present application should all be included within the scope of the claims of the present application.
Claims
1. A method for processing state data based on blockchain, characterized in that: include: Obtain data processing tasks through the target node in the blockchain; When the data processing task is a status data writing task, the status data to be written is stored in the status database of the target node, and the block number corresponding to the status data to be written is added to the first queue of the target node, wherein the block number is the number corresponding to the block that triggers the update of the status data; When the data processing task is a state data reading task, determining the block number corresponding to the state data of the current version of the blockchain, obtaining a target block number, and determining whether the target block number exists in the first queue of the target node, wherein the state data reading task is a task of reading the state data in the state database of the target node when the target node performs transaction simulation execution during the blockchain endorsement phase; If the target block number exists in the first queue, read the status data corresponding to the target block number from the status database of the target node; Wherein, before reading the status data corresponding to the target block number from the status database of the target node, the method further includes: adjusting the initial number of references in the snapshot where the target block number is located to obtain a first number of references, wherein the first number of references is used to indicate that the status data corresponding to the snapshot is referenced by the status data reading task; after reading the status data corresponding to the target block number from the status database of the target node, the method further includes: adjusting the first number of references to obtain a second number of references, wherein the second number of references is used to indicate that the status data corresponding to the snapshot has been referenced by the status data reading task.
2. The method according to claim 1, characterized in that Adding the block number corresponding to the status data to be written to the first queue of the target node includes: Determine an initial reference count of the block number corresponding to the status data to be written, wherein the initial reference count is used to indicate that the status data corresponding to the block number has not been referenced by the status data reading task; The initial reference count and the block number are combined into a snapshot, and the snapshot is stored at the end of the first queue.
3. The method according to claim 1, characterized in that After determining whether the target block number exists in the first queue of the target node, the method further includes: If the target block number does not exist in the first queue, determining an initial reference count of the target block number, wherein the initial reference count is used to indicate that the state data corresponding to the target block number has not been referenced by the state data reading task; The reference count and the target block number are combined into a snapshot, and the snapshot is stored at the end of the first queue.
4. The method according to claim 1, wherein After adjusting the first citation count to obtain a second citation count, the method further includes: Determining whether the second reference count of the snapshot is equal to the initial reference count; When the second reference count is equal to the initial reference count, the snapshot is moved from the first queue to a second queue.
5. The method according to claim 4, characterized in that After moving the snapshot from the first queue to the second queue, the method further includes: Determine the block number of the snapshot in the second queue to obtain the invalid block number; The snapshot in the second queue is deleted, and the status data corresponding to the failed block number is deleted from the status database.
6. The method according to claim 1, characterized in that The status data reading task is triggered by a transaction task. After reading the status data corresponding to the target block number from the status database of the target node, the method further includes: Executing the transaction task according to the status data corresponding to the target block number to obtain an execution result; A status data writing task is created according to the execution result.
7. A device for processing state data based on blockchain, characterized in that: include: An acquisition unit, used to acquire data processing tasks through a target node in the blockchain; a first data processing unit configured to, when the data processing task is a status data writing task, store the status data to be written in a status database of the target node, and add a block number corresponding to the status data to be written to a first queue of the target node, wherein the block number is a number corresponding to a block that triggers an update of the status data; a second data processing unit, configured to, when the data processing task is a state data reading task, determine the block number corresponding to the state data of the current version of the blockchain, obtain a target block number, and determine whether the target block number exists in the first queue of the target node. The state data reading task is a task of reading state data from a state database on the target node when the target node performs transaction simulation execution during the blockchain endorsement phase; a reading unit, configured to read, when the target block number exists in the first queue, status data corresponding to the target block number from a status database of the target node; The device further includes: a first adjustment unit, configured to adjust the initial number of references in the snapshot where the target block number is located, to obtain a first number of references, wherein the first number of references is used to indicate that the status data corresponding to the snapshot is referenced by the status data reading task; and a second adjustment unit, configured to adjust the first number of references, to obtain a second number of references, wherein the second number of references is used to indicate that the status data corresponding to the snapshot has been referenced by the status data reading task.
8. A computer storage medium, characterized in that The computer storage medium is used to store a program, wherein when the program is running, the device where the computer storage medium is located is controlled to execute the blockchain-based state data processing method according to any one of claims 1 to 6.
9. An electronic device, characterized in that: The system comprises one or more processors and a memory, wherein the memory is used 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 implement the blockchain-based state data processing method according to any one of claims 1 to 6.
Citation Information
Patent Citations
Writing method of state database, data processing device and storage medium
CN111241061A