Blockchain storage optimization method and device based on data auditing and storage medium
Patent Information
- Application Number
- CN202311632271.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-11-30
- Publication Date
- 2026-09-18
- Estimated Expiration
- 2043-11-30
AI Technical Summary
[0003]本申请提供一种基于数据稽核的区块链存储优化方法、设备及存储介质,用以解决现有技术中区块链上的数据随着无效数据增多、存储量增大,带来存储效率低和资源浪费的技术问题
[0074] This application provides a blockchain storage optimization method, apparatus, device, and storage medium based on data auditing. It acquires a predetermined number of consecutive audit blocks and their data and status information from the blockchain's origin at preset time intervals. The data information includes audit logic and audit standard data. The audit logic compares the audit standard data with the off-chain data to be audited to determine if the off-chain data is abnormal and whether its status information is valid or invalid. Based on the status information, the audit blocks are distinguished into invalid and valid blocks. The invalidity ratio is calculated based on the number of invalid blocks and a preset number. When the invalidity ratio exceeds a preset threshold, the data information of the valid blocks is re-stored on the blockchain, and the valid blocks are changed to invalid blocks. The data information of the currently existing invalid blocks is compressed. When the invalidity ratio is less than or equal to the preset threshold, the data information of the invalid blocks is compressed. By analyzing the status of the audit blocks and determining whether the number of invalid blocks meets preset conditions, different compression methods are used to compress the blocks, reducing the storage space occupied by invalid data and improving storage efficiency.
Smart Images

Figure CN117609563B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data processing, and in particular to a blockchain storage optimization method, device and storage medium based on data auditing. Background Technology
[0002] A blockchain is a chain of blocks linked together in chronological order of their creation, with each block storing specific information. When the data stored on the blockchain changes, a new block is created, increasing the blockchain's length. Current technologies store audit logic and comparison data on the blockchain during data auditing. This allows verification of the company's current data against the comparison data on the blockchain, identifying any anomalies. However, in practice, business development often leads to changes in audit data. In such cases, a new block needs to be created on the blockchain, and the original block needs to be invalidated. This approach causes the blockchain to grow longer with each new block, wasting significant storage resources and reducing storage efficiency. Summary of the Invention
[0003] This application provides a blockchain storage optimization method, device, and storage medium based on data auditing, to solve the technical problems of low storage efficiency and resource waste caused by the increase in invalid data and storage volume on the blockchain in the prior art.
[0004] Firstly, this application provides a blockchain storage optimization method based on data auditing, including:
[0005] According to a preset time interval, starting from the origin of the blockchain, a preset number of consecutive audit blocks and data information and status information of each audit block are obtained; the data information includes audit logic and audit standard data; wherein, the audit logic is used to compare the audit standard data and the off-chain data to be audited to determine whether the off-chain data to be audited is abnormal, and the status information is valid or invalid.
[0006] Based on the status information, the audit blocks are distinguished into invalid blocks and valid blocks;
[0007] The invalidity percentage is obtained based on the number of invalid blocks and the preset number.
[0008] When the invalidity ratio exceeds a preset threshold, the data information of the valid block is re-stored on the blockchain, the valid block is changed to an invalid block, and the data information of the currently existing invalid block is compressed.
[0009] When the invalidity rate is less than or equal to a preset threshold, the data information of the invalid block is compressed.
[0010] In one possible design, the data information of the valid block is re-stored on the blockchain, and the valid block is changed to an invalid block. Data compression is then performed on the data information of the currently existing invalid block, including:
[0011] Based on the data information within the valid blocks, an audit block is regenerated and stored at the end of the blockchain;
[0012] By changing the status information of the valid block to invalid, the valid block is made into an invalid block;
[0013] Data compression is performed on the data information of the original invalid blocks and the modified invalid blocks.
[0014] In one possible design, after changing the valid block to an invalid block, the method further includes:
[0015] Obtain the generation time of each invalid block in the predetermined number of consecutive invalid blocks;
[0016] The first identity identifier of the first invalid block and the second identity identifier of the last invalid block are obtained based on the generation time of each invalid block.
[0017] The identification conditions are obtained based on the second identity identifier, wherein the identification conditions are those that satisfy the block validity verification.
[0018] Based on the first identity identifier, a replacement identifier that meets the identifier conditions is generated through random number verification;
[0019] A replacement block is generated based on the replacement identifier.
[0020] In one possible design, when the invalidity percentage is less than or equal to a preset threshold, after compressing the data information of the invalid blocks, the method further includes:
[0021] Obtain the identity identifier corresponding to each audit block;
[0022] The blockchain is divided into regions based on the position of the valid blocks on the blockchain, resulting in multiple replacement regions. Each replacement region includes one or more consecutive invalid blocks.
[0023] A replacement block corresponding to each replacement area is generated based on the identity identifier.
[0024] In one possible design, generating the replacement block corresponding to each replacement region based on the identity identifier includes:
[0025] Obtain the third identity identifier of the valid block at the front end of the replacement area and the fourth identity identifier of the last invalid block within the replacement area.
[0026] Extract identification conditions from the fourth identity identifier, wherein the identification conditions are those that satisfy the block validity verification;
[0027] Based on the third identity identifier, a replacement identifier that meets the identifier conditions is generated through random number verification;
[0028] A replacement block is generated based on the replacement identifier.
[0029] In one possible design, the method further includes:
[0030] Obtain the storage space of the blockchain;
[0031] The storage space is compared with a preset space threshold;
[0032] When the storage space is less than the preset space threshold, the invalid blocks after data compression are deleted.
[0033] In one possible design, before acquiring the data and status information for each audit block, the method further includes:
[0034] Obtain the target block from the blockchain that corresponds to the off-chain data to be audited. The target block stores the audit logic and audit standard data corresponding to the off-chain data to be audited.
[0035] The audit logic is used to compare the off-chain data to be audited with the audit standard data to determine whether the off-chain data to be audited is consistent with the audit standard data.
[0036] If the off-chain data to be audited is inconsistent with the audit standard data, the status information of the target block is marked as invalid, and a new audit block is generated at the end of the blockchain according to the off-chain data to be audited and the audit logic, and the status information of the new audit block is marked as valid.
[0037] Secondly, this application provides a blockchain storage optimization device based on data auditing, comprising:
[0038] The acquisition module is used to acquire a preset number of consecutive audit blocks and data information and status information of each audit block, starting from the origin of the blockchain, at preset time intervals. The data information includes audit logic and audit standard data. The audit logic is used to compare the audit standard data and the off-chain data to be audited to determine whether the off-chain data to be audited is abnormal, and the status information is valid or invalid.
[0039] The differentiation module is used to differentiate the audit blocks into invalid blocks and valid blocks based on the status information;
[0040] The comparison module is used to obtain the invalidity percentage based on the number of invalid blocks and the preset number;
[0041] The migration module is used to re-store the data information of the valid block on the blockchain and change the valid block to an invalid block when the invalid proportion is greater than a preset threshold, and to compress the data information of the currently existing invalid block.
[0042] The compression module is used to compress the data information of the invalid blocks when the invalid percentage is less than or equal to a preset threshold.
[0043] In one possible design, the migration module is specifically used for:
[0044] Based on the data information within the valid blocks, an audit block is regenerated and stored at the end of the blockchain;
[0045] By changing the status information of the valid block to invalid, the valid block is made into an invalid block;
[0046] Data compression is performed on the data information of the original invalid blocks and the modified invalid blocks.
[0047] In one possible design, the migration module is specifically used for:
[0048] Obtain the generation time of each invalid block in the predetermined number of consecutive invalid blocks;
[0049] The first identity identifier of the first invalid block and the second identity identifier of the last invalid block are obtained based on the generation time of each invalid block.
[0050] The identification conditions are obtained based on the second identity identifier, wherein the identification conditions are those that satisfy the block validity verification.
[0051] Based on the first identity identifier, a replacement identifier that meets the identifier conditions is generated through random number verification;
[0052] A replacement block is generated based on the replacement identifier, and the replacement block replaces the preset number of consecutive invalid blocks.
[0053] In one possible design, the compression module is specifically used for:
[0054] Obtain the identity identifier corresponding to each audit block;
[0055] The blockchain is divided into regions based on the position of the valid blocks on the blockchain, resulting in multiple replacement regions. Each replacement region includes one or more consecutive invalid blocks.
[0056] Based on the identity identifier, a replacement block is generated for each replacement area, and the corresponding replacement area is replaced with the replacement block.
[0057] In one possible design, the compression module is specifically used for:
[0058] Obtain the third identity identifier of the valid block at the front end of the replacement area and the fourth identity identifier of the last invalid block in the replacement area;
[0059] Extract identification conditions from the fourth identity identifier, wherein the identification conditions are those that satisfy the block validity verification;
[0060] Based on the third identity identifier, a replacement identifier that meets the identifier conditions is generated through random number verification;
[0061] A replacement block is generated based on the replacement identifier.
[0062] In one possible design, the compression module is specifically used for:
[0063] Obtain the storage space of the blockchain;
[0064] The storage space is compared with a preset space threshold;
[0065] When the storage space is less than the preset space threshold, the invalid blocks after data compression are deleted.
[0066] In one possible design, the acquisition module is specifically used for:
[0067] Obtain the target block from the blockchain that corresponds to the off-chain data to be audited. The target block stores the audit logic and audit standard data corresponding to the off-chain data to be audited.
[0068] The audit logic is used to compare the off-chain data to be audited with the audit standard data to determine whether the off-chain data to be audited is consistent with the audit standard data.
[0069] If the off-chain data to be audited is inconsistent with the audit standard data, the status information of the target block is marked as invalid, and a new audit block is generated at the end of the blockchain according to the off-chain data to be audited and the audit logic, and the status information of the new audit block is marked as valid.
[0070] Thirdly, this application provides a blockchain storage optimization device based on data auditing, including: a processor, and a memory communicatively connected to the processor;
[0071] The memory stores the instructions that the computer executes;
[0072] The processor executes computer execution instructions stored in memory, causing a path query device accessing network resources to execute any of the data audit-based blockchain storage optimization methods in the first aspect.
[0073] Fourthly, this application provides a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, are used to implement the data audit-based blockchain storage optimization method as described in any of the first aspects.
[0074] This application provides a blockchain storage optimization method, apparatus, device, and storage medium based on data auditing. It acquires a predetermined number of consecutive audit blocks and their data and status information from the blockchain's origin at preset time intervals. The data information includes audit logic and audit standard data. The audit logic compares the audit standard data with the off-chain data to be audited to determine if the off-chain data is abnormal and whether its status information is valid or invalid. Based on the status information, the audit blocks are distinguished into invalid and valid blocks. The invalidity ratio is calculated based on the number of invalid blocks and a preset number. When the invalidity ratio exceeds a preset threshold, the data information of the valid blocks is re-stored on the blockchain, and the valid blocks are changed to invalid blocks. The data information of the currently existing invalid blocks is compressed. When the invalidity ratio is less than or equal to the preset threshold, the data information of the invalid blocks is compressed. By analyzing the status of the audit blocks and determining whether the number of invalid blocks meets preset conditions, different compression methods are used to compress the blocks, reducing the storage space occupied by invalid data and improving storage efficiency. Attached Figure Description
[0075] 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.
[0076] Figure 1This is a flowchart illustrating the blockchain storage optimization method based on data auditing provided in the embodiments of this application. Figure 1 ;
[0077] Figure 2 This is a flowchart illustrating the blockchain storage optimization method based on data auditing provided in the embodiments of this application. Figure 2 ;
[0078] Figure 3 This is a flowchart illustrating the blockchain storage optimization method based on data auditing provided in the embodiments of this application. Figure 3 ;
[0079] Figure 4 This is a flowchart illustrating the blockchain storage optimization method based on data auditing provided in the embodiments of this application. Figure 4 ;
[0080] Figure 5 This is a flowchart illustrating the blockchain storage optimization method based on data auditing provided in the embodiments of this application. Figure 5 ;
[0081] Figure 6 This is a schematic diagram of the structure of the blockchain storage optimization device based on data auditing provided in the embodiments of this application;
[0082] Figure 7 This is a schematic diagram of the hardware structure of the blockchain storage optimization device based on data auditing provided in the embodiments of this application.
[0083] The accompanying drawings illustrate specific embodiments of this application, which will be described in more detail below. These drawings and descriptions are not intended to limit the scope of the concept in any way, but rather to illustrate the concept of this application to those skilled in the art through reference to particular embodiments. Detailed Implementation
[0084] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0085] In existing technologies, when conducting data audits using blockchain, the audit logic and results are stored on the blockchain. This allows verification of the consistency between the currently audited data and the results on the blockchain, thus determining if there are any anomalies. When the audited data changes, a new block needs to be created on the blockchain, resulting in an increase in the number of blocks. This application addresses this by checking a preset number of audit blocks in the blockchain header. When the number of invalid blocks in the header reaches a threshold, different compression methods are used to compress the blocks, reducing the storage space occupied by invalid data and improving storage efficiency.
[0086] The blockchain storage optimization method based on data auditing provided in this application aims to solve the above-mentioned technical problems of existing technologies.
[0087] The technical solution of this application and how the technical solution of this application solves the above-mentioned technical problems are described in detail below with specific embodiments. These specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments. The embodiments of this application will now be described with reference to the accompanying drawings.
[0088] Figure 1 This is a flowchart illustrating a blockchain storage optimization method based on data auditing, as described in an embodiment of the present invention. Figure 1 ,like Figure 1 As shown, this embodiment provides a blockchain storage optimization method based on data auditing, which includes the following steps:
[0089] Step S101: At a preset time interval, starting from the origin of the blockchain, obtain a preset number of consecutive audit blocks and the data information and status information of each audit block; the data information includes audit logic and audit standard data; wherein, the audit logic is used to compare the audit standard data and the off-chain data to be audited in order to determine whether the off-chain data to be audited is abnormal, and the status information is valid or invalid.
[0090] Specifically, the preset time interval can be set according to actual needs to periodically optimize the data on the blockchain. Since blockchain data is stored chronologically, if the off-chain data to be audited is inconsistent with the audit standard data during data auditing, the target block's state information needs to be marked as invalid. A new audit block is then generated at the end of the blockchain based on the off-chain data to be audited and the audit logic. The new audit block's state information is valid, thus increasing the number of invalidated audit blocks at the blockchain's head. Therefore, each optimization process starts from the origin of the blockchain and analyzes a preset number of consecutive audit blocks.
[0091] Step S102: Based on the status information, the audit blocks are distinguished to obtain invalid blocks and valid blocks.
[0092] Specifically, an invalid block occurs when the off-chain data to be audited changes due to business development or other reasons, becoming inconsistent with the audit standard data on the blockchain. When a new audit block needs to be generated based on the off-chain data to be audited, the current audit standard data becomes invalid, and the audit block containing it is marked as invalid. A valid block occurs when the off-chain data to be audited is consistent with the audit standard data during the audit process, and the corresponding audit block status information remains unchanged; or when there was inconsistency between the off-chain data to be audited and the audit standard data during a previous audit process, and a new audit block is generated on the blockchain based on the off-chain data to be audited and the audit logic.
[0093] Step S103: Obtain the invalidity percentage based on the number of invalid blocks and the preset number.
[0094] Specifically, by calculating the ratio of invalid blocks to the total number of audit blocks, it is easier to check whether the conditions for migrating valid blocks are met.
[0095] Step S104: When the invalidity ratio is greater than the preset threshold, the data information of the valid blocks will be re-stored on the blockchain, the valid blocks will be changed to invalid blocks, and the data information of the currently existing invalid blocks will be compressed.
[0096] Specifically, the preset threshold can be adjusted based on the blockchain's storage capacity and actual needs. If the blockchain has a large storage space, the preset threshold can be reduced. When the invalid percentage exceeds the preset threshold, valid blocks are re-stored at the end of the blockchain, and then the obtained consecutive preset number of audit blocks are compressed to release a large amount of storage space.
[0097] Step S105: When the invalid percentage is less than or equal to a preset threshold, compress the data information of the invalid blocks.
[0098] Specifically, when the invalidity rate is less than or equal to a preset threshold, it indicates that there are a large number of valid blocks among the preset number of consecutive audit blocks obtained. If the above method of re-storing valid blocks at the end of the blockchain and then compressing all the preset number of consecutive audit blocks is adopted, a large amount of data needs to be processed, resulting in a large workload and slow optimization speed and low efficiency. However, compressing only invalid blocks does not affect the normal storage of valid blocks and can also release a certain amount of storage space, thus achieving the purpose of storage optimization.
[0099] The blockchain storage optimization method based on data auditing provided in this invention analyzes the status of audit blocks and determines whether the number of invalid blocks meets preset conditions, thereby using different compression methods to compress the blocks, reducing the storage space occupied by invalid data and improving storage efficiency.
[0100] Figure 2 A flowchart illustrating the blockchain storage optimization method based on data auditing provided in this application embodiment. Figure 2 .like Figure 2 As shown, this embodiment provides a detailed description of the optimization process when the invalidity ratio exceeds a preset threshold, as described in the above embodiment. The specific implementation of this process includes the following steps:
[0101] Step S201: Based on the data information in the valid blocks, regenerate the audit block at the end of the blockchain and store it.
[0102] Specifically, since the blocks will be temporarily inaccessible after compression, this process of migrating data from valid blocks is to ensure that after all the subsequently obtained consecutive audit blocks of a preset number are compressed, normal access to the data within the valid blocks will not be affected.
[0103] Step S202: Change the status information of the valid block to invalid, thus turning the valid block into an invalid block.
[0104] Specifically, after migrating valid blocks, in order to prevent duplicate blocks from causing data access anomalies before data compression, the status information of valid blocks is immediately changed to invalid after the migration is completed, ensuring the uniqueness and integrity of on-chain data when auditing off-chain data is required.
[0105] Step S203: Compress the data information of the original invalid block and the modified invalid block.
[0106] Specifically, since the original number of valid blocks was small, after data migration, all the audit blocks that were obtained in a continuous preset number have been turned into invalid blocks. The entire area is an invalid area, and all the data in it is invalid and has no access value. Therefore, by compressing the data information of the original invalid blocks and the modified invalid blocks, the storage space is released.
[0107] Figure 3 A flowchart illustrating the blockchain storage optimization method based on data auditing provided in this application embodiment. Figure 3 .like Figure 3 As shown, this embodiment provides a detailed explanation of the process of replacing invalid blocks after changing valid blocks to invalid blocks in the above embodiment. The specific implementation of this process includes the following steps:
[0108] Step S301: Obtain the generation time of each invalid block in a consecutive preset number of invalid blocks.
[0109] Specifically, since audit blocks on the blockchain are generated in chronological order of audit time, each audit block retains the identity identifier of the previous block. By obtaining the generation time, it is convenient to arrange the audit blocks.
[0110] Step S302: Obtain the first identity identifier of the first invalid block and the second identity identifier of the last invalid block based on the generation time of each invalid block.
[0111] Specifically, when generating a replacement block, it is necessary to carry the identity identifier of the first invalid block and generate an identity identifier that meets the conditions of the second identity identifier.
[0112] Step S303: Obtain the identification conditions based on the second identity identifier. The identification conditions are the identification conditions that satisfy the block validity verification.
[0113] Specifically, only after passing the validity verification can the corresponding audit block be found based on the identity identifier. Furthermore, the identity identifier of the next audit block is generated based on the identity identifier of the replacement block. In order to avoid affecting the identity identifier of subsequent blocks, the identity identifier with the same validity as the second identity identifier is generated by obtaining the identifier conditions.
[0114] Step S304: Generate a replacement identifier that meets the identifier conditions based on the first identity identifier by means of random number verification.
[0115] Specifically, the identity identifier of each block on the blockchain is calculated based on the identity identifier of the previous block. Since the obtained consecutive preset number of audit blocks are all invalid blocks, in order to ensure that the identity identifier of the replacement block does not affect the identity identifier of the next block, it is necessary to generate a replacement identifier that meets the identifier conditions based on the first identity identifier through random number verification.
[0116] Step S305: Generate a replacement block based on the replacement identifier.
[0117] Specifically, the replacement block is a blank block that does not store any data content. It only stores the third-party identity identifier of the valid front-end block and the generated replacement identifier.
[0118] Figure 4 A flowchart illustrating the blockchain storage optimization method based on data auditing provided in this application embodiment. Figure 4 .like Figure 4As shown in the example, this embodiment details the process of replacing invalid blocks by generating replacement blocks when the invalidity ratio is less than or equal to a preset threshold, as described in the above embodiment. The specific implementation of this process includes the following steps:
[0119] Step S401: Obtain the identity identifier corresponding to each audit block.
[0120] Specifically, when generating a replacement block, it is necessary to base it on the identity identifier of the previous block.
[0121] Step S402: Divide the blockchain into regions according to the position of the valid blocks on the blockchain to obtain multiple replacement regions. Each replacement region includes one or more consecutive invalid blocks.
[0122] Specifically, when dividing the region, in order to replace it with a replacement block later, each replacement region, whether it is a single invalid block or multiple consecutive invalid blocks, is replaced by a replacement block to reduce the storage space occupied by invalid blocks.
[0123] Step S403: Obtain the third identity identifier of the valid block at the front of the replacement area and the fourth identity identifier of the last invalid block in the replacement area.
[0124] Specifically, when generating a replacement block, it is necessary to carry the identity identifier of the previous valid block and generate an identity identifier that meets the conditions of the identity identifier of the last invalid block in the replacement area.
[0125] Step S404: Extract the identification conditions from the fourth identity identifier. The identification conditions are the identification conditions that satisfy the block validity verification.
[0126] Specifically, when searching for audit blocks, validity verification is required to find the corresponding audit block based on the identity identifier. Furthermore, the identity identifier of the next valid audit block on the blockchain is generated based on the identity identifier of the replacement block. The condition for obtaining the identifier is to generate an identity identifier with the same validity as the identity identifier of the last invalid block in the replacement area, so as to avoid affecting the identity identifier of subsequent blocks.
[0127] Step S405: Generate a replacement identifier that meets the identifier conditions based on the third identity identifier through random number verification.
[0128] Specifically, the identity identifier of each block on the blockchain is calculated based on the identity identifier of the previous block. In order to ensure that replacing the identity identifier of a block does not affect the identity identifier of the next valid audit block on the blockchain, it is necessary to generate a replacement identifier that meets the identifier conditions based on a third identity identifier through random number verification.
[0129] Step S406: Generate a replacement block based on the replacement identifier.
[0130] Specifically, the replacement block is a blank block that does not store any data content. It only stores the third-party identity identifier of the valid front-end block and the generated replacement identifier.
[0131] This application embodiment also provides a process for deleting invalid blocks: obtaining the storage space of the blockchain; comparing the storage space with a preset space threshold; and deleting the invalid block after data compression when the storage space is less than the preset space threshold.
[0132] Specifically, in existing blockchain networks, when deleting a node, a consensus is initiated for the transaction request to delete that node. After consensus is reached, the consensus node executes the transaction to delete the node, sequentially numbering the remaining consensus nodes (excluding the node to be deleted). This process requires the joint action of all blockchain nodes. This solution, by generating replacement blocks, avoids affecting the identity of all remaining blocks after deleting invalid blocks, effectively reducing data processing volume without requiring the participation of all blocks. After generating the replacement block, there are two paths from the starting node to the valid block node: the first path is from the starting node to the valid block node via the replacement block, and the second path is from the starting node to the valid block node via the compressed invalid block. When storage space on the blockchain is limited, the compressed invalid block can be deleted to free up blockchain storage space; when storage space on the blockchain is relatively abundant, the deletion of the compressed invalid block can be omitted.
[0133] Figure 5 A flowchart illustrating the blockchain storage optimization method based on data auditing provided in this application embodiment. Figure 5 .like Figure 5 As shown, this embodiment details the process of auditing data on the blockchain before obtaining the data and status information of each audit block in the above embodiment. The specific implementation of this process includes the following steps:
[0134] Step S501: Obtain the target block corresponding to the off-chain data to be audited from the blockchain. The target block stores the audit logic and audit standard data corresponding to the off-chain data to be audited.
[0135] Specifically, when data auditing is required, since the blockchain stores corresponding standard data, it is necessary to access the target block that stores the audit standard data based on the block's identity identifier. Then, the off-chain data to be audited and the audit standard data are compared according to the audit logic stored in the target block to check for any data inconsistencies.
[0136] Step S502: Based on the audit logic, compare the data under the audit chain to be audited with the audit standard data to determine whether the data under the audit chain to be audited is consistent with the audit standard data.
[0137] Specifically, since data can change dynamically due to business development or other reasons, by comparing the off-chain data to be audited with the audit standard data according to the audit logic, it can be determined whether there are any anomalies in the off-chain data to be audited. If there are anomalies, the data stored on the blockchain needs to be updated to facilitate the next audit.
[0138] Step S503: If the off-chain data to be audited is inconsistent with the audit standard data, the status information of the target block is marked as invalid, and a new audit block is generated at the end of the blockchain according to the off-chain data to be audited and the audit logic, and the status information of the new audit block is marked as valid.
[0139] Specifically, this process involves updating the data on the blockchain after auditing the data. When data inconsistencies exist, the current data needs to be stored on the chain as the standard data for the next audit. Since each block stores the corresponding audit standard, during the data audit process, the existing off-chain data to be audited is compared with the originally stored audit standard data. When the data changes, the state of the target block is adjusted to invalid, and all data in the target block becomes invalid. By marking the state information of the target block as invalid, and using the off-chain data to be audited as the audit standard data for the next audit along with the audit logic, a new audit block is generated at the end of the blockchain. The state information of the new audit block is then marked as valid, completing the data update.
[0140] Figure 6 This is a schematic diagram of the structure of a blockchain storage optimization device based on data auditing, provided in an embodiment of the present invention. Figure 6 As shown, the blockchain storage optimization device 60 based on data auditing includes: an acquisition module 601, a differentiation module 602, a comparison module 603, a migration module 604, and a compression module 605.
[0141] The acquisition module 601 is used to acquire a preset number of consecutive audit blocks and the data information and status information of each audit block, starting from the origin of the blockchain, at preset time intervals. The data information includes audit logic and audit standard data. The audit logic is used to compare the audit standard data and the off-chain data to be audited to determine whether the off-chain data to be audited is abnormal and whether the status information is valid or invalid.
[0142] The differentiation module 602 is used to differentiate audit blocks into invalid blocks and valid blocks based on status information.
[0143] The comparison module 603 is used to obtain the invalidity percentage based on the number of invalid blocks and the preset number.
[0144] The migration module 604 is used to re-store the data information of the valid blocks on the blockchain and change the valid blocks to invalid blocks when the invalid proportion is greater than a preset threshold, and to compress the data information of the currently existing invalid blocks.
[0145] Compression module 605 is used to compress the data information of invalid blocks when the invalid percentage is less than or equal to a preset threshold.
[0146] In one possible design, migration module 604 is specifically used for:
[0147] Based on the data information within the valid blocks, an audit block is regenerated and stored at the end of the blockchain;
[0148] By changing the status information of a valid block to invalid, a valid block becomes an invalid block.
[0149] Data compression is performed on the data information of the original invalid blocks and the modified invalid blocks.
[0150] In one possible design, migration module 604 is further used for:
[0151] Get the generation time of each invalid block in a consecutive preset number of invalid blocks;
[0152] The first identity identifier of the first invalid block and the second identity identifier of the last invalid block are obtained based on the generation time of each invalid block.
[0153] The identification conditions are obtained based on the second identity identifier, and the identification conditions are those that satisfy the block validity verification.
[0154] A replacement identifier that meets the identifier conditions is generated based on the first identity identifier through random number verification;
[0155] Replacement blocks are generated based on the replacement identifier, and a preset number of consecutive invalid blocks are replaced by replacement blocks.
[0156] In one possible design, the compression module 605 is further used for:
[0157] Obtain the identity identifier corresponding to each audit block;
[0158] The blockchain is divided into regions based on the position of valid blocks on the blockchain, resulting in multiple replacement regions. Each replacement region includes one or more consecutive invalid blocks.
[0159] Generate a replacement block for each replacement area based on the identity identifier, and replace the corresponding replacement area with the replacement block.
[0160] In one possible design, the compression module 605 is further used for:
[0161] Obtain the third identity identifier of the valid block at the front of the replacement area and the fourth identity identifier of the last invalid block in the replacement area;
[0162] Extract the identification conditions from the fourth identity identifier. The identification conditions are the identification conditions that satisfy the block validity verification.
[0163] A substitute identifier that meets the identifier conditions is generated based on a third-party identity identifier through random number verification;
[0164] A replacement block is generated based on the replacement identifier.
[0165] In one possible design, the compression module 605 is further used for:
[0166] Obtain storage space on the blockchain;
[0167] Compare the storage space with a preset space threshold;
[0168] When the storage space is less than the preset space threshold, the invalid blocks after data compression will be deleted.
[0169] In one possible design, module 601 is further used for:
[0170] Obtain the target block from the blockchain that corresponds to the off-chain data to be audited. The target block stores the audit logic and audit standard data corresponding to the off-chain data to be audited.
[0171] Based on the audit logic, the off-chain data to be audited is compared with the audit standard data to determine whether the off-chain data to be audited is consistent with the audit standard data.
[0172] If the off-chain data to be audited is inconsistent with the audit standard data, the status information of the target block will be marked as invalid, and a new audit block will be generated at the end of the blockchain based on the off-chain data to be audited and the audit logic. The status information of the new audit block will then be marked as valid.
[0173] The blockchain storage optimization device based on data auditing provided in this embodiment can be used to execute the blockchain storage optimization method based on data auditing described above. Its implementation principle and technical effect are similar, and will not be repeated here.
[0174] Figure 7 This is a schematic diagram of the hardware structure of a blockchain storage optimization device based on data auditing provided in an embodiment of the present invention, as shown below. Figure 7As shown, the blockchain storage optimization device 70 based on data auditing includes at least one processor 701 and a memory 702. Optionally, the blockchain storage optimization device 70 based on data auditing also includes a communication component 703. The processor 701, memory 702, and communication component 703 are connected via a bus 704.
[0175] In the specific implementation process, at least one processor 701 executes computer execution instructions stored in memory 702, causing at least one processor 701 to execute the above-mentioned blockchain storage optimization method based on data auditing.
[0176] The communication component 703 can interact with the server.
[0177] The specific implementation process of processor 701 can be found in the above method embodiments, and its implementation principle and technical effect are similar. It will not be repeated here.
[0178] In the embodiments shown in 7 above, it should be understood that the processor can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), etc. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the method disclosed in this invention can be directly implemented by a hardware processor, or implemented by a combination of hardware and software modules within the processor.
[0179] The memory may include high-speed RAM, and may also include non-volatile storage (NVM), such as at least one disk storage.
[0180] The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. Buses can be categorized as address buses, data buses, control buses, etc. For ease of illustration, the buses shown in the accompanying drawings are not limited to a single bus or a single type of bus.
[0181] This application also provides a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, implement the above-described blockchain storage optimization method based on data auditing.
[0182] The aforementioned computer-readable storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk. The readable storage medium can be any available medium accessible to a general-purpose or special-purpose computer.
[0183] An exemplary readable storage medium is coupled to a processor, enabling the processor to read information from and write information to the readable storage medium. Of course, the readable storage medium can also be a component of the processor. The processor and the readable storage medium can reside in an Application Specific Integrated Circuit (ASIC). Alternatively, the processor and the readable storage medium can exist as discrete components in the device.
[0184] The division of units is merely a logical functional division; in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be indirect coupling or communication connection through some interfaces, devices, or units, and may be electrical, mechanical, or other forms.
[0185] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0186] In addition, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.
[0187] If a function is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0188] Those skilled in the art will understand that all or part of the steps of the above-described method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When executed, the program performs the steps of the above-described method embodiments; and the aforementioned storage medium includes various media capable of storing program code, such as ROM, RAM, magnetic disks, or optical disks.
[0189] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.
Claims
1. A blockchain storage optimization method based on data auditing, characterized in that, include: According to a preset time interval, starting from the origin of the blockchain, a preset number of consecutive audit blocks and data information and status information of each audit block are obtained; the data information includes audit logic and audit standard data; wherein, the audit logic is used to compare the audit standard data and the off-chain data to be audited to determine whether the off-chain data to be audited is abnormal, and the status information is valid or invalid. Based on the status information, the audit blocks are distinguished into invalid blocks and valid blocks; The invalidity percentage is obtained based on the number of invalid blocks and the preset number. When the invalidity ratio exceeds a preset threshold, the data information of the valid block is re-stored on the blockchain, the valid block is changed to an invalid block, and the data information of the currently existing invalid block is compressed. When the invalid percentage is less than or equal to a preset threshold, the data information of the invalid block is compressed. The data information of the valid block is re-stored on the blockchain, and the valid block is changed to an invalid block. Data compression is performed on the data information of the currently existing invalid block, including: Based on the data information within the valid blocks, an audit block is regenerated and stored at the end of the blockchain; By changing the status information of the valid block to invalid, the valid block is made into an invalid block; Data compression is performed on the data information of the original invalid blocks and the modified invalid blocks.
2. The method according to claim 1, characterized in that, After changing the valid block to an invalid block, the method further includes: Obtain the generation time of each invalid block in the predetermined number of consecutive invalid blocks; The first identity identifier of the first invalid block and the second identity identifier of the last invalid block are obtained based on the generation time of each invalid block. The identification conditions are obtained based on the second identity identifier, wherein the identification conditions are those that satisfy the block validity verification. Based on the first identity identifier, a replacement identifier that meets the identifier conditions is generated through random number verification; A replacement block is generated based on the replacement identifier.
3. The method according to claim 1, characterized in that, When the invalid percentage is less than or equal to a preset threshold, the method further includes compressing the data information of the invalid blocks. Obtain the identity identifier corresponding to each audit block; The blockchain is divided into regions based on the position of the valid blocks on the blockchain, resulting in multiple replacement regions. Each replacement region includes one or more consecutive invalid blocks. A replacement block corresponding to each replacement area is generated based on the identity identifier.
4. The method according to claim 3, characterized in that, The step of generating a replacement block corresponding to each replacement region based on the identity identifier includes: Obtain the third identity identifier of the valid block at the front end of the replacement area and the fourth identity identifier of the last invalid block in the replacement area; Extract identification conditions from the fourth identity identifier, wherein the identification conditions are those that satisfy the block validity verification; Based on the third identity identifier, a replacement identifier that meets the identifier conditions is generated through random number verification; A replacement block is generated based on the replacement identifier.
5. The method according to any one of claims 2 to 4, characterized in that, The method further includes: Obtain the storage space of the blockchain; The storage space is compared with a preset space threshold; When the storage space is less than the preset space threshold, the invalid blocks after data compression are deleted.
6. The method according to any one of claims 1 to 4, characterized in that, Before acquiring the data and status information of each audit block, the method further includes: Obtain the target block from the blockchain that corresponds to the off-chain data to be audited. The target block stores the audit logic and audit standard data corresponding to the off-chain data to be audited. The audit logic is used to compare the off-chain data to be audited with the audit standard data to determine whether the off-chain data to be audited is consistent with the audit standard data. If the off-chain data to be audited is inconsistent with the audit standard data, the status information of the target block is marked as invalid, and a new audit block is generated at the end of the blockchain according to the off-chain data to be audited and the audit logic, and the status information of the new audit block is marked as valid.
7. A blockchain storage optimization device based on data auditing, characterized in that, include: The acquisition module is used to acquire a preset number of consecutive audit blocks and data information and status information of each audit block, starting from the origin of the blockchain, at preset time intervals. The data information includes audit logic and audit standard data. The audit logic is used to compare the audit standard data and the off-chain data to be audited to determine whether the off-chain data to be audited is abnormal, and the status information is valid or invalid. The differentiation module is used to differentiate the audit blocks into invalid blocks and valid blocks based on the status information; The comparison module is used to obtain the invalidity percentage based on the number of invalid blocks and the preset number; The migration module is used to re-store the data information of the valid block on the blockchain and change the valid block to an invalid block when the invalid proportion is greater than a preset threshold, and to compress the data information of the currently existing invalid block. A compression module is used to compress the data information of the invalid blocks when the invalid percentage is less than or equal to a preset threshold. The migration module is specifically used to regenerate an audit block at the end of the blockchain based on the data information in the valid block and store it. By changing the status information of the valid block to invalid, the valid block is made into an invalid block; Data compression is performed on the data information of the original invalid blocks and the modified invalid blocks.
8. A blockchain storage optimization device based on data auditing, characterized in that, include: A processor, and a memory communicatively connected to the processor; The memory stores computer-executed instructions; The processor executes computer execution instructions stored in the memory to implement the method as described in any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when executed by a processor, are used to implement the method as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Data credible processing method and device, storage medium and electronic equipment
CN113222744A
Business specification uplink auditing method and device, equipment and storage medium
CN116911794A