Data processing method and device based on block chain, equipment and medium
By merging blockchain operation records in the cache and transferring them to the hard disk when the threshold is reached, the problem of frequent hard disk writing in blockchain data processing is solved, reducing hard disk energy consumption and wear, and extending hard disk life.
Patent Information
- Application Number
- CN202310707116.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-06-14
- Publication Date
- 2024-12-17
AI Technical Summary
In the prior art, when data processing in blockchain, frequent hard disk write operations lead to excessive pressure on the hard disk, increased energy consumption, and it is difficult to effectively reduce the number of write operations.
By detecting and combining operation records of the same operation objects in the cache, the number of operation records when writing to the hard disk is reduced, and the data in the cache is transferred to the hard disk when the data amount reaches the preset threshold, realizing timing writing.
It reduces the writing frequency of the hard disk, reduces the energy consumption and wear of the hard disk, extends the life of the hard disk, and relieves the writing pressure of the hard disk.
Smart Images

Figure CN119151534A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer science, and more specifically to a data processing method, apparatus, device, and medium based on blockchain. Background Technology
[0002] Blockchain is a decentralized, distributed ledger technology that uses a chain of linked blocks and a consensus mechanism to ensure the security and traceability of transactions.
[0003] During the block generation process, a large amount of transaction information is generated. Each transaction information can indicate data such as transaction amount or assets, transaction sender, transaction receiver, and signature. This will result in changes to some user status information, such as user balance and assets. This user status information can be updated based on the operation records generated by the transaction information.
[0004] In related technologies, a large number of operation records are often written to the database on the hard drive, and it is also necessary to ensure that these operation records are written immediately; otherwise, if a system crash occurs, the data cannot be recovered. This results in a large number of write operations being performed on the hard drive in a short period of time, causing excessive pressure on the hard drive and increasing its power consumption.
[0005] Therefore, how to reduce the number of write operations when storing data is an urgent problem to be solved. Summary of the Invention
[0006] To address the aforementioned technical problems, embodiments of this application provide a blockchain-based data processing method, apparatus, device, and computer-readable storage medium, which can reduce the number of write operations when storing data.
[0007] The technical solution adopted in this application is as follows:
[0008] A blockchain-based data processing method includes:
[0009] Retrieve the first operation record corresponding to the block to be processed;
[0010] If a second operation record matching the first operation object corresponding to the first operation record is detected in the cache, the second operation record is updated based on the first operation record to obtain the updated operation record;
[0011] Obtain the relationship between the amount of data in the operation records stored in the cache and a preset data amount threshold;
[0012] If the relationship indicates that the amount of data reaches a preset data volume threshold, then the operation records stored in the cache are transferred to the hard disk.
[0013] A blockchain-based data processing device includes:
[0014] The acquisition unit is used to acquire the first operation record corresponding to the block to be processed.
[0015] The processing unit is configured to update the second operation record based on the first operation record if it detects that a second operation record matching the first operation object stored in the cache is stored in the first operation record, so as to obtain the updated operation record;
[0016] The acquisition unit is also used to acquire the relationship between the amount of data of the operation records stored in the cache and the preset data amount threshold;
[0017] A storage unit is used to transfer the operation records stored in the cache to the hard disk if the data volume represented by the relationship reaches a preset data volume threshold.
[0018] In one embodiment of this application, based on the foregoing scheme, the processing unit is further configured to: if the first operation record corresponds to an update type, replace the type corresponding to the second operation record with the update type, and replace the state value corresponding to the second operation record with the state value corresponding to the first operation record; wherein the state value is used to characterize the value obtained after operating on the state data of the first operation object; if the first operation record corresponds to a deletion type, replace the type corresponding to the second operation record with the deletion type, and clear the state value corresponding to the second operation record.
[0019] In one embodiment of this application, based on the foregoing scheme, the processing unit is further configured to directly add the first operation record to the cache if the cache does not store an operation record that matches the first operation object corresponding to the first operation record.
[0020] In one embodiment of this application, based on the foregoing scheme, the acquisition unit is further configured to acquire a second operation object corresponding to the operation record stored in the hard disk; the processing unit is further configured to update the operation record in the hard disk that matches the second operation object based on the operation record in the cache that matches the second operation object, so as to obtain the updated operation record, thereby realizing the transfer of the operation record stored in the cache.
[0021] In one embodiment of this application, based on the foregoing scheme, the hard disk further stores maximum block height information; after updating the operation record in the hard disk that matches the second operation object based on the operation record in the cache to obtain the updated operation record, the acquisition unit is further configured to acquire the block height value corresponding to the terminated operation record in the cache; the processing unit is further configured to update the maximum block height information to the block height value corresponding to the terminated operation record.
[0022] In one embodiment of this application, based on the foregoing scheme, if the transceiver unit receives a power-off command before obtaining the first operation record corresponding to the block to be processed, the obtaining unit is further configured to obtain the block height value corresponding to the start operation record and the block height value corresponding to the aborted operation record of the operation records stored in the cache; the processing unit is further configured to associate the stored operation record, the block height value corresponding to the start operation record, and the block height value corresponding to the aborted operation record to obtain associated data; and store the associated data in the hard disk; wherein, the associated data is used to restore the operation record, the block height value corresponding to the start operation record, and the block height value corresponding to the aborted operation record stored in the cache after receiving a start command.
[0023] In one embodiment of this application, based on the foregoing scheme, if the transceiver unit receives a start command, the acquisition unit is further configured to acquire the associated data from a designated area of the hard disk; the processing unit is further configured to parse the associated data to obtain the stored operation record, the block height value corresponding to the start operation record, and the block height value corresponding to the aborted operation record; and to acquire the first operation record based on the block height value corresponding to the start operation record and the maximum block height information in the hard disk.
[0024] In one embodiment of this application, based on the foregoing scheme, the processing unit is further configured to: if the block height value corresponding to the starting operation record matches the maximum block height information, then obtain the block to be processed based on the block height value corresponding to the aborted operation record and the latest block height value in the blockchain, and obtain the first operation record based on the transactions in the block to be processed; if the block height value corresponding to the starting operation record does not match the maximum block height information, then obtain the block to be processed based on the maximum block height information and the latest block height value in the blockchain, and obtain the first operation record based on the transactions in the block to be processed.
[0025] In one embodiment of this application, based on the foregoing scheme, the processing unit is further configured to, after transferring the operation records stored in the cache to the hard disk, if it is detected that any operation record stored in the cache has not been successfully transferred to the hard disk, backtrack to the operation record stored on the hard disk before the transfer.
[0026] In one embodiment of this application, based on the foregoing scheme, the transceiver unit is further configured to receive a query instruction for a specified operation record; the processing unit is further configured to, if the specified operation record is found in the cache, return a query value based on the operation type included in the specified operation record; if the specified operation record is not found in the cache, query the specified operation record in the hard disk.
[0027] In one embodiment of this application, based on the foregoing scheme, the processing unit is further configured to: if the operation type included in the specified operation record is an update type, use the status value corresponding to the specified operation record as the query value and return the query value; if the operation type included in the specified operation record is a delete type, set the query value to null and return the query value.
[0028] A blockchain-based data processing device includes a processor and a memory. The memory stores computer-readable instructions, which, when executed by the processor, implement the blockchain-based data processing method described above.
[0029] A computer-readable storage medium storing computer-readable instructions that, when executed by a computer's processor, cause the computer to perform the blockchain-based data processing method described above.
[0030] A computer program product includes computer-readable instructions that, when executed by a processor, implement the blockchain-based data processing method described above.
[0031] In the above technical solution:
[0032] On one hand, after obtaining the first operation record, it's possible to check in the cache whether another operation record (i.e., a second operation record) exists for the same first operation object. If it exists, the second operation record can be updated based on the first operation record, thus reducing the number of operation records for the same operation object from two to one. When transferring the operation record to the hard drive, only the updated operation record needs to be written, instead of writing each operation record separately, thereby reducing the number of write operations to the hard drive. Therefore, this method can reduce the frequency of hard drive write operations, reduce hard drive power consumption and wear, and improve hard drive lifespan.
[0033] On the other hand, when the amount of data in the cache reaches a preset data volume threshold, the operation records stored in the cache are transferred to the hard disk, realizing the timed transfer of operation records. This avoids frequent write operations to the hard disk, further reducing the number of writes to the hard disk and lowering the power consumption of the hard disk.
[0034] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and do not limit this application. Attached Figure Description
[0035] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application. It is obvious that the drawings described below are merely some embodiments of this application, and those skilled in the art can obtain other drawings based on these drawings without any inventive effort. In the drawings:
[0036] Figure 1 This is a schematic diagram of one implementation environment involved in this application;
[0037] Figure 2 This is a flowchart illustrating a blockchain-based data processing method according to an exemplary embodiment;
[0038] Figure 3 This is a flowchart illustrating a blockchain-based data processing method according to another exemplary embodiment;
[0039] Figure 4a This is a schematic diagram illustrating the process of updating a second operation record when the first operation record corresponds to an update type, according to an exemplary embodiment.
[0040] Figure 4b This is a schematic diagram illustrating the process of updating a second operation record when a first operation record corresponds to a deletion type, according to an exemplary embodiment.
[0041] Figure 5 This is a flowchart illustrating a blockchain-based data processing method according to another exemplary embodiment;
[0042] Figure 6 This is a flowchart illustrating a blockchain-based data processing method according to another exemplary embodiment;
[0043] Figure 7 This is a flowchart illustrating a blockchain-based data processing method according to another exemplary embodiment;
[0044] Figure 8 This is a flowchart illustrating a blockchain-based data processing method according to another exemplary embodiment;
[0045] Figure 9 This is a flowchart illustrating a blockchain-based data processing method according to another exemplary embodiment;
[0046] Figure 10 This is a flowchart illustrating a full node response query command according to an exemplary embodiment;
[0047] Figure 11 This is a flowchart illustrating a blockchain-based data processing method according to another exemplary embodiment;
[0048] Figure 12 This is a block diagram illustrating a blockchain-based data processing apparatus according to an exemplary embodiment;
[0049] Figure 13 This is a schematic diagram of the hardware structure of a blockchain-based data processing device according to an exemplary embodiment. Detailed Implementation
[0050] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments identical to those of this application. Rather, they are merely examples of apparatuses and methods identical to some aspects of this application as detailed in the appended claims.
[0051] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities can be implemented in software, in one or more hardware modules or integrated circuits, or in different network and / or processor devices and / or microcontroller devices.
[0052] The flowcharts shown in the accompanying drawings are merely illustrative and do not necessarily include all content and operations / steps, nor do they necessarily need to be performed in the described order. For example, some operations / steps can be broken down, while others can be integrated or partially integrated; therefore, the actual execution order may change depending on the specific circumstances.
[0053] It should be noted that "multiple" as mentioned in this application refers to two or more. "And / or" describes the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A alone, A and B simultaneously, or B alone. The character " / " generally indicates that the preceding and following related objects have an "or" relationship.
[0054] It should be noted that in the specific implementation of this application, user-related data is involved. When the embodiments of this application are applied to specific products or technologies, user permission or consent is required, and the collection, use and processing of related data must comply with the relevant laws, regulations and standards of the relevant countries and regions.
[0055] Before introducing the technical solutions of the embodiments of this application, let's first introduce the technical terms involved in the embodiments of this application.
[0056] Blockchain is a distributed, decentralized database technology that organizes and stores data in the form of blocks and uses cryptographic algorithms to ensure data security and trustworthiness. Each block contains a batch of transaction information, linked together by hashes to form an immutable chain structure, recording a series of verified transactions and state changes. Each block contains a large amount of transaction information. A transaction is an operation of value exchange or data transfer between participants in the blockchain network. A transaction may contain information such as sender, receiver, transaction amount, and timestamp; the specific content depends on the design of the blockchain and the application scenario.
[0057] A wealth of state data can be obtained from these transaction records. State data reflects the current state of various accounts, assets, permissions, and so on within the blockchain system. For example, in a cryptocurrency blockchain, state data can represent each user's balance, account, and assets; in a supply chain management blockchain, state data can represent the current location and status of products.
[0058] State data can be included in operation records. Operation records describe state changes and operations during transaction execution. These records can be included in a block write set, which is a collection specifically used to store operation records. In this embodiment, the operation record includes at least information about the operation object involved in the transaction (which can be represented using a primary key), the operation type (such as update or delete), the state value (which can be represented using a value), and the specific content of the operation.
[0059] The purpose of operation logs is to detect and record state changes during transaction execution to ensure the correctness and consistency of transactions.
[0060] In data management and database fields, a primary key is a field or set of fields used to uniquely identify each record in a database table. Primary keys have the following characteristics:
[0061] Uniqueness: The value of the primary key must be unique throughout the entire table, meaning that each record has a unique primary key value.
[0062] Non-nullability: The value of the primary key cannot be null, that is, each record must have a valid primary key value.
[0063] A primary key serves as a unique identifier for each record in a database table. It can be used to quickly find and access specific records, and also as a basis for establishing relationships between data. Typically, the value of a primary key field can be a number, string, or other data type, depending on the database's support and the application's needs.
[0064] A compression layer is a data processing layer or component used to reduce data storage space and improve data processing efficiency. In this application embodiment, the compression layer can refer to a technology used to compress and optimize data storage in a blockchain scenario. It typically resides above the hard drive and is responsible for processing and optimizing operation records to reduce storage space usage and improve system performance. The compression layer in this application can merge multiple operation records with the same primary key or object, thereby reducing the storage of duplicate data and improving data access efficiency.
[0065] A full node is a node in a blockchain network that possesses a complete copy of the blockchain data. It is a participant in the network responsible for maintaining and verifying the integrity and security of the entire blockchain. Specifically, a full node stores complete blockchain data, including all transaction records and state data. It can independently verify the validity of transactions and participate in block generation and consensus processes. Full nodes maintain network consistency by interacting with other nodes and disseminating transaction and block information.
[0066] In related technologies, when writing operation records to the hard drive, a large number of operation records are often written directly to the hard drive. In order to avoid data loss due to the inability to write operation records because of a crash, it is also necessary to ensure that these operation records are written immediately. This will result in a large number of write operations on the hard drive in a short period of time, causing excessive pressure on the hard drive and increasing hard drive power consumption.
[0067] Based on this, embodiments of this application propose a blockchain-based data processing method, a blockchain-based data processing device, a blockchain-based data processing equipment, a computer-readable storage medium, and a computer program product. In these embodiments, operation records for the same operation object can be merged in the cache, ensuring that one operation object corresponds to only one operation record. Thus, when writing to the hard disk, one operation object only needs to be written to the operation record once, reducing the number of writes to the hard disk and reducing hard disk power consumption.
[0068] Please see Figure 1 , Figure 1 This is a schematic diagram of one implementation environment involved in this application.
[0069] Figure 1 The implementation environment shown specifically includes a blockchain 110 and a full node 140. The full node 140 includes a cache 120 and a hard disk 130.
[0070] Cache 120 and hard disk 130 can be deployed on full node 140, which can access blockchain 110 to obtain the latest state of each block in the blockchain in real time. Full node 140 can obtain each block on the blockchain and save it, writing it to hard disk 130. It should be noted that the blockchain-based data processing method of this application can be applied to full node 140 or to nodes connected to other full nodes, such as light nodes. This application does not limit the nodes to which this method is applied; any node that can obtain block information, block write set information, and includes cache and hard disk, can be used as the node for which the blockchain-based data processing method of this application is applied, under reasonable scenarios. For ease of description, this application uses full node 140 as an example for illustration.
[0071] Cache 120 is a cache memory, specifically a compression layer, used to retrieve block write sets from blockchain 110. These block write sets include multiple operation records. Furthermore, one block can correspond to one block write set, and cache 120 can retrieve the block write sets corresponding to each block from blockchain 110 sequentially for appropriate data processing. Cache 120 includes the start block height, end block height, and multiple operation records.
[0072] The starting block height represents the minimum block height value among the blocks corresponding to the operation records currently stored in cache 120; that is, it represents which block the operation records are stored from. For example, a starting block height of 684 indicates that the operation records currently stored in cache 120 start from the 684th block in the blockchain.
[0073] The start block height represents the smallest block height value corresponding to the operation record currently stored in cache 120. It identifies the starting position of the operation record in the cache, i.e., from which block the operation record begins to be stored. For example, if the start block height is 684, it means that the operation record currently stored in cache 120 starts from the 684th block in the blockchain. This value helps determine the range of operation records in cache 120 and their corresponding blockchain positions, facilitating subsequent operations and queries.
[0074] It should be noted that when cache 120 contains no operation records, a preset value (such as -1, -2, etc.) can be used to indicate that cache 120 is currently empty. This helps full node 140 to make judgments and handle cached data.
[0075] The end block height indicates the maximum block height of the block corresponding to the operation record currently stored in cache 120. It represents the end position of the operation record in cache 120, i.e., which block's operation record is currently stored. For example, if the end block height is 694, then the operation record currently stored in cache 120 has reached block 690 in the blockchain. Combining this with the example above where the start block height is 684, it shows that the operation records in cache 120 currently originate from between blocks 684 and 690.
[0076] It should be noted that when the starting block height is a preset value, it means that the current cache 120 is empty. The ending block height can be set to another preset value (e.g., -1, -2, etc.), or the ending block height can be left empty; there is no limitation here. This makes it easier to determine the status of cache 120.
[0077] Setting the start block height and end block height helps determine the range of operation records in cache 120 and perform appropriate processing when necessary. By checking the end block height, cache 120 can determine whether the stored operation records have reached a certain capacity or time range, so as to perform corresponding operations, such as writing the operation records to disk 130 or performing other processing.
[0078] Each operation record in cache 120 includes at least a primary key, an operation type, and a status value. The key can indicate the status data of an operation object (such as balance, assets, account, etc.); the operation type can indicate what operation action is required on the status data of the operation object indicated by the key, such as update or delete; the status value is the value corresponding to the status data of the operation object. For example, when the status data is RMB balance, the status value is 500, indicating that the balance of the operation object is 500 yuan; as another example, when the status data is virtual currency account, the status value is 600, indicating that the operation object has 600 virtual currency accounts.
[0079] For example, Figure 1 The operation record corresponding to key1 includes the value of key1, operation type 1, and value1. Key1 can indicate the status data of operation object 1; operation type 1 can be an update type, meaning the status data corresponding to key1 needs to be updated; value1 represents the status value corresponding to the status data of operation object 1. For example, Figure 1 The operation type 2 corresponding to key3 can be a delete type. In this case, the value corresponding to key3 will be empty.
[0080] The hard disk 130 includes at least 5 storage areas, namely storage area 1 to storage area 5.
[0081] Storage area 1 can be used to store all blocks in blockchain 110, and records the block height value (represented by height) of each block, as well as each transaction in each block, and the two can be stored in a corresponding manner. The block height value of each block can be obtained by reading the block header information of each block.
[0082] Storage area 2 is used to store the block height value of the latest block stored in storage area 1, i.e., the latest block height value. This latest block height value can be identified by a key named "Last height", and can be read by using this key. Here, "Last height" is only an example name, and those skilled in the art can change it to other suitable names.
[0083] Storage area 3 is used to store the operation records transferred from cache 120. The operation records in storage area 3 may not include the operation type; that is, they may include key and value. Before the operation records stored in the compression layer are transferred to the hard disk, the status data corresponding to each operation record can be updated based on all stored operation records, without needing to store the operation type on the hard disk. Optionally, the operation type corresponding to each key can be stored in another storage area for subsequent queries. Therefore, storage area 3 can store keys and corresponding values, where the value reflects the status value of the corresponding user's status data.
[0084] Storage area 4 is used to store the maximum block height information of the block to which the operation record stored in storage area 3 belongs. This maximum block height information can be identified by a key named "State height," and can be read using this "State height" key. Here, "State height" is merely an example name, and those skilled in the art can change it to other suitable names.
[0085] Storage area 5 is used to store associated data, which is the value obtained after serializing all data in cache 120 (such as start block height, end block height, and stored operation records). This associated data can be identified by a key named "journal," and can be read using this "journal" key. Here, "journal" is only an example name, and those skilled in the art can change it to other suitable names.
[0086] Please see Figure 2 , Figure 2 This is a flowchart illustrating a blockchain-based data processing method according to an exemplary embodiment. The method can be applied to... Figure 1 The implementation environment is shown, and it is specifically executed by a full node. Of course, this method can also be applied to other implementation environments, and there are no restrictions on the subject executing this method.
[0087] The following section will use a full node as an example to illustrate this blockchain-based data processing method in detail. For ease of description, this application will... Figure 1 The cache 120 in the text is described as a compression layer.
[0088] like Figure 2 As shown, in an exemplary embodiment, the method includes at least the following steps:
[0089] S210, obtain the first operation record corresponding to the block to be processed.
[0090] A full node obtains a block to be processed from the blockchain, and then obtains the block write set corresponding to the transactions in the block to be processed. The block write set includes a first operation record, which can be any operation record in the block write set.
[0091] The block write set can be obtained from the transaction information in the block to be processed. For each transaction, the transaction data can be parsed to extract relevant operation record information, thereby obtaining the block write set. This block write set can be generated by a full node or automatically generated after the block to be processed is added to the blockchain. This application embodiment does not limit the specific method of generating the block write set.
[0092] In one embodiment of this application, if the current compression layer already contains some operation records and is in normal operation, the compression layer can obtain the block to be processed based on the current end block height value. That is, the block to be processed is the block corresponding to the next block height value after the end block height value. For example, if the current end block height value of the compression layer is 690, then the full node can obtain the 691st block from the blockchain, use it as the block to be processed, and thus obtain the first operation record in it.
[0093] In one embodiment of this application, if the current compression layer is operating normally and the starting block height in the current compression layer is a preset value (e.g., -1), it indicates that there are no operation records in the current compression layer. Then, the block height of the block to be processed can be obtained based on the maximum block height information stored on the hard drive. For example, if the maximum block height information on the hard drive is 683, then it can be determined that the 684th block on the blockchain needs to be obtained as the block to be processed.
[0094] S220, if it is detected that there is a second operation record in the cache that matches the first operation object corresponding to the first operation record, then the second operation record is updated based on the first operation record to obtain the updated operation record.
[0095] When a full node detects that there is a second operation record in the compression layer that matches the first operation object corresponding to the first operation record, it can perform an update process.
[0096] Specifically, the primary key in the first operation record can be read to determine that the first operation record is operating on the first operation object. Then, the compression layer is queried to see if there is another operation record for the first operation object, i.e., a second operation record. At this time, the compression layer will store two operation records for the first operation object. Therefore, the first operation record and the second operation record need to be merged to change the number of operation records for the first operation object to one.
[0097] When a full node merges the first operation record and the second operation record, it can update the second operation record based on the first operation record to obtain the updated operation record.
[0098] It should be noted that when updating the second operation record based on the first operation record, different update processes will occur depending on the different operation records included in the first and second operation records.
[0099] In one embodiment of this application, if the compression layer does not store an operation record that matches the first operation object corresponding to the first operation record, the first operation record is directly added to the compression layer. This means that a new operation record will be added to the compression layer, which corresponds to the first operation record, and an operation object record matching the first operation record will also be added to the compression layer. This ensures that the operation record in the compression layer is synchronized with the actual first operation record and provides accurate data for subsequent processing and querying.
[0100] S230, obtain the relationship between the amount of data in the operation records stored in the cache and the preset data amount threshold.
[0101] The full node can obtain the preset data volume threshold, which is used to determine whether the amount of data in the compressed layer that has been stored has reached or exceeded the threshold. The size of the preset data volume threshold can be appropriately adjusted according to the amount of data in the current compressed layer that has been stored.
[0102] A full node can understand the current storage status of the compression layer by counting the amount of data of operation records stored in the current compression layer, and compare it with a preset data volume threshold to obtain the relationship between the two.
[0103] S240, if the amount of data representing the relationship reaches a preset data amount threshold, then the operation records stored in the cache are transferred to the hard disk.
[0104] In one embodiment of this application, if the difference between the amount of data of the operation record stored in the compressed layer and the preset data volume threshold is small (e.g., less than the difference threshold, such as 3M), it can be considered to be within a tolerable range. The data volume is considered to have reached the preset data volume threshold, and the operation record can be directly transferred to the hard disk without dynamically changing the preset data volume threshold. The size of this difference threshold can be adjusted by those skilled in the art according to the actual application scenario, and is not limited here.
[0105] In one embodiment of this application, if the difference between the amount of data of operation records stored in the compression layer and a preset data amount threshold is large (e.g., greater than or equal to the difference threshold), it is necessary to consider dynamically changing the preset data amount threshold. A full node can detect the amount of data of operation records in the next block to be processed on the blockchain, add it to the amount of data of operation records currently stored in the compression layer, and then compare the summed data amount with the preset data amount threshold.
[0106] Optionally, if the difference between the summed data size and the preset data size threshold is still large, the next block to be processed can be obtained, processed and stored, and the data size of the operation record in the next block to be processed can be detected until the difference between the data of the operation record stored in the compression layer and the preset data size threshold is small, or exceeds the preset data size threshold.
[0107] For example, assuming the preset data volume threshold is set at 100M, the difference threshold is 3M, the current compressed layer contains 90M of operation records, and the full node detects that the next block to be processed contains approximately 5M of operation records. The full node can then process and save the next block, reducing the data volume in the compressed layer to 95M, which is still significantly different from the preset data volume threshold (i.e., greater than or equal to 3M). The full node will then detect the next block to be processed, assuming it is 4M. The full node can then process and save this next block, reducing the data volume in the compressed layer to 99M, which is less than the preset data volume threshold (i.e., less than 3M). Therefore, the 99M of operation records in the current compressed layer can be transferred to the hard drive.
[0108] Optionally, if the sum of the above data exceeds a preset data size threshold, the preset data size threshold can be dynamically changed to match the sum of the data. By dynamically changing the threshold, the threshold can be adjusted based on the data size of the current compression layer and the next block to be processed, ensuring that the compression layer has sufficient storage space to process the operation records of the next block and reducing the number of writes to the hard drive.
[0109] For example, suppose the preset data volume threshold is set to 100M, the gap threshold is 3M, the current compressed layer has 90M of operation records stored, and the full node detects that the next block to be processed will have approximately 20M of operation records. In this case, directly transferring the 90M of operation records to the hard drive would waste 10M of compressed layer storage space. Therefore, in this situation, the full node can set the preset data volume threshold to 110M to ensure that the compressed layer has sufficient storage space to process the operation records of the next block.
[0110] By adjusting the preset data volume threshold and making reasonable use of the compression layer's storage space, the number of write operations to the hard drive can be reduced to some extent, thereby improving system performance and reducing hard drive power consumption. At the same time, it is necessary to determine an appropriate preset data volume threshold and storage strategy based on system requirements and resource constraints to balance storage space utilization and performance requirements.
[0111] It should be noted that if the full node dynamically changes the preset data size threshold, it will adjust the threshold back to its initial state after transferring the operation records from the compression layer to the hard drive. For example, if the preset data size threshold was 110M, it will be adjusted back to 100M. This ensures that the same preset data size threshold is used in the next compression layer process, thus maintaining consistency in processing standards and strategies.
[0112] In one embodiment of this application, if it is detected that any operation record stored in the compression layer has failed to be successfully transferred to the hard disk, the process is to revert to the operation record stored on the hard disk before the transfer. That is, in this application, when the compression layer transfers operation records to the hard disk, it can use an atomic writing method. If the writing of one operation record fails, it is considered that all operation records written in this instance have failed, and all operation records on the hard disk need to be reverted to the state before the compression layer wrote the operation record.
[0113] This method updates operation records for the same operation object in the cache, ensuring that each operation object in the cache contains only one operation record. When transferring operation records from the cache to disk for writing, each operation object's operation record is written only once, eliminating the need to write all operation records for that operation object in the block write set to disk, significantly reducing the number of disk writes. Furthermore, operation records are only transferred to disk for writing when the amount of data in the cache reaches a preset threshold, achieving timed writing of operation records and increasing the time interval between adjacent writes, further alleviating the write pressure on the disk.
[0114] In one embodiment of this application, another blockchain-based data processing method is provided, which can be executed by a full node. For example... Figure 3 As shown, this blockchain-based data processing method may include steps S210, S310 to S320, and S230 to S240. That is, steps S310 to S320 are... Figure 2 The specific implementation method of S220 is shown.
[0115] The following describes S310 to S320:
[0116] S310, if it is detected that a second operation record is stored in the cache that matches the first operation object corresponding to the first operation record, and the first operation record corresponds to an update type, then the update type is used to replace the type corresponding to the second operation record, and the status value corresponding to the second operation record is used to replace the status value corresponding to the first operation record.
[0117] The first operation record is any operation record in the block write set corresponding to the block that the compression layer is currently processing.
[0118] When the operation type in the first operation record is an update type, it indicates that the status data corresponding to the key of the first operation object needs to be updated. Therefore, the full node can replace the update type of the second operation record with the update type of the first operation record. This status data can be information such as the account, balance, and assets of the first operation object.
[0119] Secondly, the full node also needs to replace the state value corresponding to the second operation record with the state value corresponding to the first operation record.
[0120] For example, such as Figure 4a The diagram illustrates the update process of a second operation record when the first operation record corresponds to an update type. Figure 4a In the compressed layer, the second operation record is already stored: key1, update, value2 (400 yuan). This second operation record is for the operation object key1, and its operation record is to update the status value to 400 yuan. The first operation record is the operation record that needs to be stored, which includes: key1, update, value1 (500 yuan). The full node can then replace the update of the second operation record with the update of the first operation record, and replace the value2 (500 yuan) of the second operation record with the value1 (400 yuan) of the first operation record. This results in the updated operation record: key1, update, value1 (500 yuan).
[0121] S320, if it is detected that a second operation record is stored in the cache that matches the first operation object corresponding to the first operation record, and the first operation record corresponds to a deletion type, then the deletion type is used to replace the type corresponding to the second operation record, and the status value corresponding to the second operation record is cleared.
[0122] When the operation type included in the first operation record is deletion, it indicates that a certain state data of the first operation object needs to be deleted. Therefore, the full node can replace the corresponding type in the second operation record with this deletion type and clear the corresponding state value. This clearing operation can refer to setting the state value to zero, empty, or a default value, etc., and is not limited here.
[0123] For example, such as Figure 4b The diagram illustrates the process of updating a second operation record when the first operation record corresponds to a deletion type. Figure 4bIn the compressed layer, the second operation record is already stored: key1, update, value2 (400 yuan). The first operation record includes: key1, delete, value1 (-). Therefore, the full node can replace the update type of the second operation record with the delete type of the first operation record, and simultaneously delete the state value Value2 (400 yuan). This results in the updated operation record: key1, delete, -.
[0124] In one embodiment of this application, after the compression layer has finished processing all operation records in the current block, it needs to update the height of the included ending block accordingly, updating it to the block height value corresponding to that block. For example, if the block is the 691st block, after processing all operation records in this block, the ending block height needs to be updated to 691. In this way, the block height corresponding to the block that the current compression layer has completed can be reflected in real time, allowing the full node to know the progress of the current compression layer in processing blocks.
[0125] This method allows for updating stored operation records in the compression layer based on newly acquired operation records for an operation object. This enables the merging and compression of multiple operation records for an operation object, reducing the number of writes to the hard disk during subsequent writing.
[0126] In one embodiment of this application, another blockchain-based data processing method is provided, which can be executed by a full node. For example... Figure 5 As shown, this blockchain-based data processing method may include S210 to S230 and S510 to S520. That is, S510 to S520 are... Figure 2 The specific implementation method of S240 is shown.
[0127] The following describes S510 to S520:
[0128] S510, if the amount of data represented by the relationship reaches a preset data amount threshold, then obtain the second operation object corresponding to the operation record stored on the hard disk.
[0129] The second operation object can be any one of the operation objects corresponding to the operation records stored on the hard disk.
[0130] S520 updates the operation record on the hard disk that matches the second operation object based on the operation record in the cache, so as to obtain the updated operation record and realize the transfer of the operation record stored in the cache.
[0131] The full node can detect the operation record matching the second operation object in the compression layer and needs to update it with the operation record on the hard disk. This update process is the same as updating the operation records already stored in the compression layer, and will not be described in detail here.
[0132] This method allows full nodes to merge operation records of the same operation object when transferring operation records from the compressed layer to the hard disk, thereby reducing the storage pressure on the hard disk and enabling it to store operation records of more operation objects.
[0133] In one embodiment of this application, another blockchain-based data processing method is provided, which can be executed by a full node. For example... Figure 6 As shown, the blockchain-based data processing method may include steps S210 to S230, S510 to S520, and S610 to S620. That is, steps S610 to S620 are... Figure 5 The method that needs to be implemented after S520 is shown.
[0134] In this embodiment of the application, the hard disk also stores the maximum block height information.
[0135] The following describes S610 to S620:
[0136] S610, retrieve the block height value corresponding to the termination operation record in the cache.
[0137] The termination operation record can be the last operation record processed by the compression layer, or the operation record in the last block that can be processed. That is, the block height value corresponding to the termination operation record is the end block height value in the compression layer at this time.
[0138] A full node can obtain the block height value corresponding to the terminated operation record. The compression layer processes the operation record by storing it, and if there are duplicate operation records for the same operation object, they need to be merged.
[0139] S620 updates the maximum block height information to the block height value corresponding to the termination operation record.
[0140] In this way, the hard drive can store the block height value corresponding to the block processed by this compression layer.
[0141] This method allows the hard drive to access the maximum block height information in the block corresponding to the currently stored operation record at any time, thereby monitoring the processing progress and storage status in real time. This information helps the full node make correct decisions and determine the next processing and operation steps.
[0142] In one embodiment of this application, another blockchain-based data processing method is provided, which can be executed by a full node. For example... Figure 7 As shown, the blockchain-based data processing method may include S710 to S730 and S210 to S240.
[0143] The following describes S710 to S730:
[0144] If the S710 receives a power-off command, it retrieves the block height value corresponding to the start operation record and the block height value corresponding to the aborted operation record stored in the cache.
[0145] The power-off command may be received by the compression layer of a full node while it is processing operation records in a block. At this time, the compression layer has already stored some operation records, and due to specific needs, it needs to temporarily exit processing. Therefore, after receiving the power-off command, the full node needs to perform a normal exit procedure. This normal exit procedure can also be called a graceful exit.
[0146] Optionally, upon receiving a power-off command, the compression layer will complete all operation records of the currently being processed block before proceeding with the normal exit procedure.
[0147] Specifically, a full node can obtain the block height value corresponding to the starting operation record stored in the compression layer, i.e., the starting block height value. It then obtains the block height value corresponding to the aborted operation record stored in the compression layer, i.e., the current ending block height value. This aborted operation record is the last operation record currently being processed by the compression layer.
[0148] It should be noted that when a full node receives a power-off command, it needs to stop the compression layer from processing the next block's operation record. Therefore, the last operation record in the compression layer at this time can be called the aborted operation record. If the full node does not receive a power-off command, the compression layer will process each block normally. When the amount of data in the operation commands in the compression layer reaches a preset data threshold, it will terminate the processing of the current batch of blocks. Therefore, the last operation record in the compression layer at this time can be called the terminated operation record.
[0149] S720 associates the stored operation record, the block height value corresponding to the start operation record, and the block height value corresponding to the stop operation record to obtain associated data.
[0150] Upon receiving a power-off command, the full node first retrieves the stored operation records, the current start block height, and the end block height from the compressed layer. Then, it correlates this information to obtain correlated data.
[0151] Optionally, a full node can serialize the stored operation records, the current start block height, and the end block height to form a serialized value, which can be represented by the value.
[0152] The S730 stores associated data on the hard drive.
[0153] The associated data is used to restore the block height values corresponding to the operation records, the start operation records, and the stop operation records stored in the cache after receiving the start command.
[0154] A full node will write the associated data to disk for storage. This associated data can be written to, for example,... Figure 1 The storage area 5 shown can persistently store the associated data.
[0155] Optionally, a primary key, "journal", can be assigned to the associated data during storage. When the associated data needs to be read later, it can be done by calling the journal primary key.
[0156] Using this method, when a full node needs to exit normally, it can serialize the data in the compressed layer to obtain associated data. Then, when the compressed layer needs to continue processing blocks after the next startup, the required information can be recovered from the associated data, ensuring the orderly execution of compressed layer storage operation records.
[0157] In one embodiment of this application, another blockchain-based data processing method is provided, which can be executed by a full node. For example... Figure 8 As shown, this blockchain-based data processing method may include S710 to S730, S810 to S830, and S220 to S240. That is, S810 to S830 are... Figure 2 The specific implementation method of S210 shown is based on the premise that S710 to S730 are executed.
[0158] The following describes S810 to S820:
[0159] If the S810 receives a boot command, it retrieves the associated data from a specified area of the hard disk.
[0160] This specified area is the area where the associated data is stored, and it can be storage area 5.
[0161] S820 parses the associated data to obtain the block height value corresponding to the stored operation record, the start operation record, and the stop operation record.
[0162] A full node parses the acquired associated data. Parsing is the process of converting serialized data back to the original data, which can be called deserialization. By parsing the associated data, a full node can extract previously stored operation records, the block height value corresponding to the start operation record, and the block height value corresponding to the aborted operation record.
[0163] S830 obtains the first operation record based on the block height value corresponding to the initial operation record and the maximum block height information in the hard disk.
[0164] The full node compares and matches the block height value corresponding to the initial operation record with the maximum block height information stored on the hard drive. The maximum block height information is data previously stored on the hard drive, recording the maximum block height value among the operation records already stored. By comparing these two block height values, the full node can determine where to obtain the first operation record to be retrieved from the compression layer.
[0165] The maximum block height information on the hard drive can be obtained by calling the primary key "State Height".
[0166] Specifically, S830 may include S831 to S832, which are described below:
[0167] S831, if the block height value corresponding to the starting operation record matches the maximum block height information, then obtain the block to be processed based on the block height value corresponding to the aborted operation record and the latest block height value in the blockchain, and obtain the first operation record based on the transactions in the block to be processed.
[0168] The latest block height in the blockchain can be obtained through the primary key "Last Height". The block height corresponding to the start operation record (i.e., the starting block height recorded when the compression layer exited normally) and the block height corresponding to the stop operation record (i.e., the ending block height recorded when the compression layer exited normally) can both be obtained through the primary key "journal".
[0169] For ease of explanation, the maximum block height information in the hard drive is denoted as S, the latest block height value in the blockchain is denoted as L, the block height value corresponding to the start operation record is called the start block height value, and the block height value corresponding to the stop operation record is called the end block height value.
[0170] Specifically, if the starting block height is equal to S+1, it means that the operation records of the several blocks processed when the compression layer exited normally last time are exactly the operation records of the blocks the hard drive needs next. In this case, the starting block height can be considered to match S. Therefore, the blocks to be processed can be obtained based on the ending block height and L. The full node obtains the blocks in the interval from the ending block height to L. These blocks can be obtained by the full node in ascending order of block height, and then the first operation record is obtained.
[0171] For example, after receiving the start command, the full node detects that S is 683, L is 750, the start block height of the compressed layer is 684, and the end block height is 690. At this time, the start block height is exactly equal to S+1, so it can obtain the next block (i.e., the 691st block) on the blockchain based on the end block height (690), and then obtain the first operation record from the 691st block.
[0172] S832, if the block height value corresponding to the initial operation record does not match the maximum block height information, then obtain the block to be processed based on the maximum block height information and the latest block height value in the blockchain, and obtain the first operation record based on the transactions in the block to be processed.
[0173] Specifically, if the starting block height is not equal to S+1, it means that the operation records of the processed blocks when the compression layer exited normally last time are not the operation records of the blocks that the hard drive needs next. In this case, the starting block height value can be considered to be mismatched with S. Therefore, the block to be processed can be obtained based on S and L, and then the first operation record can be obtained.
[0174] For example, after receiving the start command, the full node detects that S is 683, L is 750, the start block height of the compressed layer is 688, and the end block height is 695. At this point, the start block height is not equal to S+1, therefore the two do not match. This may be because the previous full node failure resulted in the compressed layer not properly storing operation records to the disk. In this case, it is necessary to clear the data in the compressed layer and restart processing from the next block after S (i.e., the 684th block), retrieving the first operation record from the 684th block.
[0175] Using this method, a full node can match the block height value of the initial operation record with the maximum block height information after startup to determine which block's operation record to start processing from. This allows the full node to continue processing operation records from the correct starting point, ensuring the correct operation record is stored on the hard drive and guaranteeing data storage accuracy.
[0176] In one embodiment of this application, another blockchain-based data processing method is provided, which can be executed by a full node. For example... Figure 9 As shown, the blockchain-based data processing method may include S910 to S930.
[0177] The following describes S910 to S930:
[0178] S910 receives a query command for a specified operation record.
[0179] The specified operation record can be any operation record, which may be stored in a compressed layer or on the hard drive. The query instruction may include the primary key to be queried.
[0180] S920: If a specified operation record is found in the cache, the query value is returned based on the operation type included in the specified operation record.
[0181] like Figure 10 As shown, the full node will first search for the key in the compressed layer according to the query command. If it is not found, it will then search for it in the hard disk.
[0182] If the operation record corresponding to the key is found in the compression layer, then the query value can be returned based on the operation type included in the specified operation record.
[0183] Optionally, if the specified operation record includes an update type operation, the status value corresponding to the specified operation record will be used as the query value and returned. For example, if the specified operation record is found in the compression layer as: key4, update, value(50 yuan), then the value(50 yuan) can be used as the query value and returned.
[0184] If the specified operation record includes an operation of type delete, the query value will be set to null and returned. This indicates that the operation object corresponding to the specified operation record currently does not have a status value with corresponding status data.
[0185] S930: If the specified operation record is not found in the cache, the specified operation record will be searched on the hard disk.
[0186] The method for querying a specific operation record on the hard drive is similar to that for querying in the compressed layer. The query command is used to locate the corresponding storage location and retrieve the corresponding operation record.
[0187] This method allows full nodes to retrieve specified operation records based on query commands. By prioritizing queries in the compressed layer, it reduces the number of disk accesses, improving query efficiency and performance. Querying first in the compressed layer leverages its high-speed reading and parsing capabilities. Only when the specified operation record is not found in the compressed layer will a more time-consuming disk query be performed.
[0188] In one embodiment of this application, another blockchain-based data processing method is provided, which can be executed by a full node. For example... Figure 11 As shown, the blockchain-based data processing method may include S1101 to S1116.
[0189] It should be noted that S1101 to S1116 are illustrated using an application scenario where blocks are processed starting from a compression layer that does not include operation records. Furthermore, S1101 to S1116 are examples of an application scenario used to exemplify the blockchain-based data processing method provided in this application.
[0190] The following describes S1101 to S1116:
[0191] S1101, the first block is processed through the compression layer.
[0192] Specifically, the compression layer can query the stored operation records for each operation record in the write set corresponding to the first block, and merge operation records with the same key. If no other operation records belonging to the same operation object are stored in the compression layer for a given operation record, then the operation record is directly stored in the compression layer. The specific merging method has been described in detail in the foregoing embodiments and will not be repeated here.
[0193] The first block can be the first block in the current compression layer. After processing the first block, the compression layer still has enough cache space to store the operation records of other blocks.
[0194] The first block can be determined based on the maximum block height information (S) stored on the hard drive, and the block height value of the first block can be S+1. For ease of explanation, the maximum block height information stored on the hard drive is denoted as S.
[0195] S1102, Update the start block height and end block height values.
[0196] After processing the operation records of the first block, the compression layer needs to set the start block height to the block height value of the first block (i.e., the block height value of the initial operation record) and the end block height value to the block height value of the first block. The block height value of the first block can be obtained from the blockchain or by reading the block header of the first block.
[0197] S1103, determine whether a power-off command has been received.
[0198] When a power-off command is received, the current end block height value can be regarded as the block height value of the operation abort command.
[0199] If received, execute S1104; if not received, execute S1111.
[0200] S1104, perform association processing on the operation records, start block height value and end block height value stored in the compressed layer to obtain associated data.
[0201] The association process can be serialization, and the associated data can be serialized data.
[0202] S1105 stores the associated data on the hard drive and then enters a power-off state.
[0203] S1106 receives the start command and enters the running state.
[0204] S1107: Retrieve associated data from the hard disk and parse it to obtain the stored operation record, start block height value, and end block height value.
[0205] S1108, retrieve S stored on the hard disk.
[0206] S1109, Check if the starting block height is equal to S+1.
[0207] If yes, it means the current compression layer is available, and S1112 is executed; if no, it means the current compression layer is unavailable, and S1110 is executed.
[0208] S1110, discard the current compressed layer, obtain a new compressed layer, and set the current processed block height value (H) to S.
[0209] Discarding the current compression layer can be achieved by setting the current compression layer to null. The new compression layer can be obtained by setting the current compression layer to null, or it can be a newly created compression layer for the entire node; there is no limitation here.
[0210] S1111, set H to the end block height value.
[0211] The ending block height value is the block height value corresponding to the stop operation record of the compression layer at this time.
[0212] S1112, determine whether H is less than the height (L) of the latest block in the blockchain.
[0213] For ease of explanation, the height of the latest block in the blockchain will be denoted as L.
[0214] Specifically, the compression layer will sequentially acquire each block in the range [H+1, L] as a block to be processed in ascending order, and then process and cache it.
[0215] If H < L, it means there are still unprocessed blocks in the blockchain, so execute S1114; if H = L, it means there are currently no unprocessed blocks in the blockchain, so execute S1113.
[0216] S1113, awaiting the H+1th block to be added to the blockchain.
[0217] If the H+1th block is detected to be on the blockchain, then execute S1114. Here, "block on-chain" refers to the process of adding a block to the blockchain.
[0218] S1114, process the H+1th block, and update at least one of the start block height value and the end block height value after processing.
[0219] Processing the H+1th block involves merging all operation records with the same key in the compression layer within the H+1th block.
[0220] If the current compression layer is empty, then after processing the H+1th block, the starting block height value needs to be updated to H+1, and the ending block height value also needs to be updated to H+1.
[0221] If the current compression layer is not empty, the end block height value needs to be updated to H+1 after processing the H+1th block. The start block height value does not need to be updated.
[0222] S1115, determine whether the amount of data in the operation records stored in the cache has reached the preset data amount threshold.
[0223] If the data volume does not reach the preset data volume threshold, then H is incremented by one, i.e., H = H + 1, to obtain the updated H, and then S1112 is executed; otherwise, S1116 is executed.
[0224] S1116, transfer the operation records stored in the compressed layer to the hard disk.
[0225] After a successful write, the full node can update S in the compressed layer to H (the block height value corresponding to the termination operation instruction in the current compressed layer) when S1116 was executed.
[0226] After a successful write, the full node can also empty the compressed layer and execute S1101 to process the operation records of the next batch of blocks (starting from the H+1th block).
[0227] It should be noted that during the normal operation of the compression layer (i.e., the normal execution of S1101 to S1102 and S1111 to S1116), if a power-off command is received at any time, the process must immediately jump to the steps after "Yes" in S1103 after the currently processed block is completed, that is, start execution from S1104.
[0228] It should be noted that the specific implementation methods of S1101 to S1116 have been described in detail in the foregoing embodiments, and will not be repeated here.
[0229] This method merges operation records for the same operation object in the compression layer, ensuring that each operation object in the cache contains only one operation record. This means that when transferring operation records from the cache to disk for writing, each operation object's operation record is written only once, eliminating the need to write all operation records for that operation object in the block write set to disk, significantly reducing the number of disk writes. Furthermore, operation records are only transferred to disk for writing when the amount of data in the cache reaches a preset threshold, achieving timed writing of operation records and increasing the time interval between two adjacent writes, further alleviating the write pressure on the disk.
[0230] Figure 12 This is a block diagram illustrating a blockchain-based data processing apparatus according to one embodiment of this application. Figure 12 As shown, this blockchain-based data processing device can be applied to full nodes, and the device includes:
[0231] The acquisition unit 1210 is used to acquire the first operation record corresponding to the block to be processed;
[0232] The processing unit 1220 is configured to update the second operation record based on the first operation record if it detects that a second operation record matching the first operation object corresponding to the first operation record is stored in the cache, so as to obtain the updated operation record.
[0233] The acquisition unit 1210 is also used to acquire the relationship between the amount of data of the operation records stored in the cache and the preset data amount threshold;
[0234] Storage unit 1230 is used to transfer the operation records stored in the cache to the hard disk if the relationship characterizes the amount of data to a preset data amount threshold.
[0235] In one embodiment of this application, based on the foregoing scheme, the processing unit 1220 is further configured to: if the first operation record corresponds to an update type, replace the type corresponding to the second operation record with the update type, and replace the state value corresponding to the second operation record with the state value corresponding to the first operation record; wherein, the state value is used to characterize the value obtained after operating on the state data of the first operation object; if the first operation record corresponds to a deletion type, replace the type corresponding to the second operation record with the deletion type, and clear the state value corresponding to the second operation record.
[0236] In one embodiment of this application, based on the foregoing scheme, the processing unit 1220 is further configured to directly add the first operation record to the cache if there is no operation record in the cache that matches the first operation object corresponding to the first operation record.
[0237] In one embodiment of this application, based on the foregoing scheme, after replacing the block height value corresponding to the second operation record with the block height value corresponding to the first operation record, the acquisition unit 1210 is further configured to acquire the state value corresponding to the first operation record; wherein, the state value is used to characterize the value obtained after operating on the state data of the first operation object; the processing unit 1220 is further configured to replace the state value corresponding to the second operation record with the state value.
[0238] In one embodiment of this application, based on the foregoing scheme, the acquisition unit 1210 is further configured to acquire the second operation object corresponding to the operation record stored in the hard disk; the processing unit 1220 is further configured to update the operation record in the hard disk that matches the second operation object based on the operation record in the cache that matches the second operation object, so as to obtain the updated operation record and realize the transfer of the operation record stored in the cache.
[0239] In one embodiment of this application, based on the foregoing scheme, the hard disk further stores maximum block height information; after updating the operation record in the hard disk that matches the second operation object based on the operation record in the cache to obtain the updated operation record, the acquisition unit 1210 is further configured to acquire the block height value corresponding to the terminated operation record in the cache; the processing unit 1220 is further configured to update the maximum block height information to the block height value corresponding to the terminated operation record.
[0240] In one embodiment of this application, based on the foregoing scheme, if the transceiver unit 1240 receives a power-off command before obtaining the first operation record corresponding to the block to be processed, the acquisition unit 1210 is further configured to acquire the block height value corresponding to the start operation record and the block height value corresponding to the aborted operation record of the operation records stored in the cache; the processing unit 1220 is further configured to associate the stored operation record, the block height value corresponding to the start operation record, and the block height value corresponding to the aborted operation record to obtain associated data; and store the associated data in the hard disk; wherein, the associated data is used to restore the operation record, the block height value corresponding to the start operation record, and the block height value corresponding to the aborted operation record stored in the cache after receiving a start command.
[0241] In one embodiment of this application, based on the foregoing scheme, if the transceiver unit 1240 receives a start command, the acquisition unit 1210 is further configured to acquire the associated data from a designated area of the hard disk; the processing unit 1220 is further configured to parse the associated data to obtain the stored operation record, the block height value corresponding to the start operation record, and the block height value corresponding to the aborted operation record; and to acquire the first operation record based on the block height value corresponding to the start operation record and the maximum block height information in the hard disk.
[0242] In one embodiment of this application, based on the foregoing scheme, the processing unit 1220 is further configured to: if the block height value corresponding to the start operation record matches the maximum block height information, then obtain the block to be processed based on the block height value corresponding to the aborted operation record and the latest block height value in the blockchain, and obtain the first operation record based on the transactions in the block to be processed; if the block height value corresponding to the start operation record does not match the maximum block height information, then obtain the block to be processed based on the maximum block height information and the latest block height value in the blockchain, and obtain the first operation record based on the transactions in the block to be processed.
[0243] In one embodiment of this application, based on the foregoing scheme, the processing unit 1220 is further configured to, after transferring the operation records stored in the cache to the hard disk, if it is detected that any operation record stored in the cache has not been successfully transferred to the hard disk, backtrack to the operation records stored on the hard disk before the transfer.
[0244] In one embodiment of this application, based on the foregoing scheme, the transceiver unit 1240 is further configured to receive a query instruction for a specified operation record; the processing unit 1220 is further configured to, if the specified operation record is found in the cache, return a query value based on the operation type included in the specified operation record; if the specified operation record is not found in the cache, query the specified operation record in the hard disk.
[0245] In one embodiment of this application, based on the foregoing scheme, the processing unit 1220 is further configured to: if the operation type included in the specified operation record is an update type, use the status value corresponding to the specified operation record as the query value and return the query value; if the operation type included in the specified operation record is a delete type, set the query value to empty and return the query value.
[0246] It should be noted that the apparatus provided in the foregoing embodiments and the method provided in the foregoing embodiments belong to the same concept, and the specific way in which each module and unit performs operations has been described in detail in the method embodiments.
[0247] Embodiments of this application also provide a blockchain-based data processing device, including: one or more processors; and a memory for storing one or more programs, which, when executed by one or more processors, enable the electronic device to implement the aforementioned blockchain-based data processing method.
[0248] Figure 13 This is a schematic diagram of the structure of a computer system suitable for implementing the blockchain-based data processing device of the present application embodiments.
[0249] It should be noted that, Figure 13 The computer system 1300 of the electronic device shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments of this application.
[0250] like Figure 13 As shown, the computer system 1300 includes a Central Processing Unit (CPU) 1301, which can perform various appropriate actions and processes, such as executing the methods described in the above embodiments, based on programs stored in Read-Only Memory (ROM) 1302 or programs loaded from storage portion 1308 into Random Access Memory (RAM) 1303. The RAM 1303 also stores various programs and data required for system operation. The CPU 1301, ROM 1302, and RAM 1303 are interconnected via a bus 1304. An Input / Output (I / O) interface 1305 is also connected to the bus 1304.
[0251] The following components are connected to I / O interface 1305: an input section 1306 including a keyboard, mouse, etc.; an output section 1307 including a cathode ray tube (CRT), liquid crystal display (LCD), etc., and speakers, etc.; a storage section 1308 including a hard disk, etc.; and a communication section 1309 including a network interface card such as a LAN (Local Area Network) card, modem, etc. The communication section 1309 performs communication processing via a network such as the Internet. A drive 1310 is also connected to I / O interface 1305 as needed. Removable media 1311, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., are installed on drive 1310 as needed so that computer programs read from them can be installed into storage section 1308 as needed.
[0252] Specifically, according to embodiments of this application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of this application include a computer program product comprising a computer program carried on a computer-readable medium, the computer program including a computer program for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via communication section 1309, and / or installed from removable medium 1311. When the computer program is executed by central processing unit (CPU) 1301, it performs various functions defined in the system of this application.
[0253] It should be noted that the computer-readable medium shown in the embodiments of this application can be a computer-readable signal medium or a computer-readable storage medium, or any combination of the two. For example, a computer-readable medium can be an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM), flash memory, optical fiber, portable compact disc read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this application, a computer-readable medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In this application, a computer-readable signal medium can include a data signal propagated in baseband or as part of a carrier wave, carrying a computer-readable computer program. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. Computer-readable signal media can also be any computer-readable medium other than computer-readable storage media, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The computer program contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to wireless, wired, etc., or any suitable combination thereof.
[0254] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this application. Each block in a flowchart or block diagram may represent a module, segment, or portion of code, which contains one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram or flowchart, and combinations of blocks in a block diagram or flowchart, may be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0255] The units described in the embodiments of this application can be implemented in software or hardware, and the described units can also be located in a processor. The names of these units do not necessarily limit the specific unit itself.
[0256] Another aspect of this application provides a computer-readable medium having a computer program stored thereon, which, when executed by a processor, implements the aforementioned blockchain-based data processing method. This computer-readable medium may be included in the electronic device described in the above embodiments, or it may exist independently and not incorporated into the electronic device.
[0257] Another aspect of this application provides a computer program product or computer program including computer instructions stored in a computer-readable medium. A processor of a computer device reads the computer instructions from the computer-readable medium and executes the computer instructions, causing the computer device to perform the blockchain-based data processing method provided in the various embodiments described above.
[0258] The above description is merely a preferred exemplary embodiment of this application and is not intended to limit the implementation of this application. Those skilled in the art can easily make corresponding modifications or alterations based on the main concept and spirit of this application. Therefore, the scope of protection of this application should be determined by the scope of protection claimed in the claims.
Claims
1. A data processing method based on blockchain, characterized in that: include: Obtaining a first operation record corresponding to the block to be processed; If it is detected that a second operation record matching the first operation object corresponding to the first operation record is stored in the cache, the second operation record is updated based on the first operation record to obtain an updated operation record; Obtaining a relationship between the data volume of the operation records stored in the cache and a preset data volume threshold; If the relationship represents that the data volume reaches a preset data volume threshold, the operation records stored in the cache are transferred to the hard disk.
2. The method according to claim 1, characterized in that The updating the second operation record based on the first operation record to obtain an updated operation record includes: If the first operation record corresponds to an update type, the type corresponding to the second operation record is replaced with the update type, and the status value corresponding to the second operation record is replaced with the status value corresponding to the first operation record; wherein the status value is used to represent the value obtained after operating the status data of the first operation object; If the first operation record corresponds to a deletion type, the type corresponding to the second operation record is replaced with the deletion type, and the status value corresponding to the second operation record is cleared.
3. The method according to claim 1, characterized in that The method further comprises: If the cache does not store an operation record that matches the first operation object corresponding to the first operation record, the first operation record is directly added to the cache.
4. The method according to claim 1 or 3, characterized in that: The transferring the operation records stored in the cache to the hard disk includes: Acquire a second operation object corresponding to the operation record stored in the hard disk; Based on the operation record in the cache that matches the second operation object, the operation record in the hard disk that matches the second operation object is updated to obtain an updated operation record, so as to achieve the transfer of the operation record stored in the cache.
5. The method according to claim 4, characterized in that The hard disk also stores maximum block height information; after the operation record matching the second operation object in the cache is updated, and the updated operation record is obtained, the method further includes: Obtaining the block height value corresponding to the termination operation record in the cache; The maximum block height information is updated to the block height value corresponding to the termination operation record.
6. The method according to claim 1 or 3, characterized in that: Before obtaining the first operation record corresponding to the block to be processed, the method further includes: If a power-off instruction is received, obtaining a block height value corresponding to a start operation record of the operation records stored in the cache, and a block height value corresponding to a stop operation record; Associating the stored operation record, the block height value corresponding to the start operation record, and the block height value corresponding to the stop operation record to obtain associated data; The associated data is stored in the hard disk; wherein the associated data is used to restore the operation record stored in the cache, the block height value corresponding to the start operation record, and the block height value corresponding to the stop operation record after receiving the start instruction.
7. The method according to claim 6, characterized in that The obtaining of the first operation record corresponding to the block to be processed includes: If a start instruction is received, acquiring the associated data from a designated area of the hard disk; Parsing the associated data to obtain the stored operation record, the block height value corresponding to the start operation record, and the block height value corresponding to the stop operation record; The first operation record is obtained based on the block height value corresponding to the starting operation record and the maximum block height information in the hard disk.
8. The method according to claim 7, characterized in that The obtaining the first operation record based on the block height value corresponding to the starting operation record and the maximum block height information in the hard disk includes: If the block height value corresponding to the start operation record matches the maximum block height information, the block to be processed is obtained based on the block height value corresponding to the stop operation record and the latest block height value in the blockchain, and the first operation record is obtained based on the transaction in the block to be processed; If the block height value corresponding to the starting operation record does not match the maximum block height information, the block to be processed is obtained based on the maximum block height information and the latest block height value in the blockchain, and the first operation record is obtained based on the transaction in the block to be processed.
9. The method according to any one of claims 1-3, 5, 7, and 8, characterized in that: After transferring the operation records stored in the cache to the hard disk, the method further includes: If it is detected that any operation record stored in the cache is not successfully transferred to the hard disk, the operation record stored in the hard disk before the transfer is traced back.
10. The method according to claim 1, characterized in that The method further comprises: Receive query instructions for specified operation records; If the specified operation record is found in the cache, a query value is returned based on the operation type included in the specified operation record; If the specified operation record is not found in the cache, the specified operation record is searched in the hard disk.
11. The method according to claim 10, characterized in that The returning a query value based on the operation type included in the specified operation record includes: If the operation type included in the designated operation record is an update type, the state value corresponding to the designated operation record is used as the query value, and the query value is returned; If the operation type included in the designated operation record is a deletion type, the query value is set to empty and the query value is returned.
12. A data processing device based on blockchain, characterized in that: include: An acquisition unit, used for acquiring a first operation record corresponding to the block to be processed; a processing unit, configured to update the second operation record based on the first operation record to obtain an updated operation record if it is detected that a second operation record matching the first operation object corresponding to the first operation record is stored in the cache; The acquisition unit is further used to acquire the relationship between the data volume of the operation records stored in the cache and a preset data volume threshold; The storage unit is used to transfer the operation records stored in the cache to the hard disk if the data volume represented by the relationship reaches a preset data volume threshold.
13. A data processing device based on blockchain, characterized in that: include: a memory storing computer-readable instructions; A processor reads the computer-readable instructions stored in the memory to execute the method according to any one of claims 1 to 11.
14. A computer-readable storage medium, characterized in that: Computer-readable instructions are stored thereon, and when the computer-readable instructions are executed by a processor of a computer, the computer is caused to execute the method according to any one of claims 1 to 11.
15. A computer program product, characterized in that The computer program product comprises a computer program, the computer program is stored in a computer-readable storage medium, a processor of an electronic device reads and executes the computer program from the computer-readable storage medium, so that the electronic device performs the method according to any one of claims 1 to 11.
