Blockchain-based data auditing method, device, equipment and storage medium

By acquiring data from the blockchain and transferring it to a linked table in the database for comparison and repair, the problem of inconsistency between blockchain and database data is solved, achieving consistency between on-chain and off-chain data.

CN115344559BActive Publication Date: 2026-02-24CHINA MOBILE GROUP ZHEJIANG +1
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202110532278.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-05-14
Publication Date
2026-02-24
Estimated Expiration
2041-05-14

AI Technical Summary

Technical Problem

In existing technologies, inconsistencies between data on the blockchain and data in the database make data auditing difficult, and existing solutions cannot effectively solve the consistency problem between on-chain and off-chain data.

Method used

By acquiring on-chain data from the previous period to the current time, transferring it to the chain transfer table of the database, obtaining comparison data from the business table of the database, and comparing it, the data on the blockchain is repaired based on the comparison results to ensure data consistency.

Benefits of technology

It achieves consistency between data on the blockchain and business table data in the database. By sampling on-chain data and transferring it to a chain transfer table, comparing it with database data, identifying and correcting discrepancies, it ensures consistency between on-chain and off-chain data.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115344559B_ABST
    Figure CN115344559B_ABST
Patent Text Reader

Abstract

The application discloses a blockchain-based data auditing method and device, equipment and a storage medium. The method comprises the following steps: acquiring chain data from a period to the current time on a blockchain; storing the chain data in a chain conversion table of a database to obtain chain conversion table data; acquiring comparison data in a business table of the database, comparing the comparison data in the business table with the chain conversion table data, and obtaining a comparison result; and repairing the data on the blockchain according to the comparison result. The chain data is sampled and stored in the chain conversion table, the data in the chain conversion table is compared with the data in the database, and difference data inconsistent between the blockchain and the database is obtained. The data on the blockchain is repaired through the difference data, so that the data on the blockchain is consistent with the data in the business table of the database, and the consistency of the on-chain and off-chain data is realized.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of block chain, and particularly relates to a data auditing method and device based on block chain, equipment and storage medium. BACKGROUND

[0002] In the prior art, the business of an operator exists multi-party interaction, including between a provincial company system and a group company system, between provincial company systems, between the provincial company system and an external partner company system, and each party system performs data interaction through a data synchronization interface. An important content in the data interaction is data auditing. A current data auditing solution is to import an auditing file into a database, compare scripts through the database, compare data record consistency and key field value consistency, and audit data consistency of both parties of a transaction.

[0003] By adopting the solution in the prior art, data is stored on a block chain in a block node mode, and a node is stored in a key\value form instead of a relational data. The existing solution does not support obtaining data on the block chain, and data on and off the chain is inconsistent. SUMMARY

[0004] The main purpose of the present application is to provide a data auditing method and device based on a block chain, equipment and storage medium, aiming to solve the technical problem of ensuring consistency of data on and off the chain.

[0005] To achieve the above purpose, the present application provides a data auditing method based on a block chain, which comprises the following steps:

[0006] Obtaining chain data on a block chain from a previous period to a current time;

[0007] Storing the chain data to a chain conversion table of a database to obtain chain conversion table data;

[0008] Obtaining comparison data in a business table of the database, comparing the comparison data in the business table with the chain conversion table data, and obtaining a comparison result;

[0009] According to the comparison result, repairing the data on the block chain to ensure consistency of the data on the block chain and the data in the business table of the database.

[0010] Optionally, the storing the chain data to the database to obtain the chain conversion table data comprises:

[0011] Obtaining node data of the chain data, and determining an order number value according to the node data;

[0012] Generating a key-value pair according to the order number value;

[0013] comparing the key-value pair with key-value pairs in a preset filter cache, wherein data in the preset filter cache is consistent with data in the database;

[0014] determining a database statement according to a comparison result;

[0015] storing the on-chain data into the database according to the database statement to obtain chain table data.

[0016] Optionally, the obtaining of the comparison data in the business table of the database, the comparison of the comparison data in the business table with the chain table data, and the obtaining of a comparison result include:

[0017] calling a multi-thread starting instruction, and obtaining a database data extraction thread and a chain table data extraction thread according to the multi-thread starting instruction;

[0018] extracting comparison data from the business table through the database data extraction thread, and extracting chain table data from the chain table through the chain table data extraction thread after a preset time interval;

[0019] comparing the comparison data in the business table with the chain table data to obtain a comparison result.

[0020] Optionally, the comparison of the comparison data in the business table with the chain table data to obtain a comparison result includes:

[0021] extracting an order number and order content in the comparison data, and generating a database key-value pair according to the order number and order content in the comparison data;

[0022] extracting an order number and order content in the chain table data, and generating a chain table key-value pair according to the order number and order content in the chain table data;

[0023] comparing the database key-value pair with the chain table key-value pair, and selecting a target chain table key-value pair that does not contain the database key-value pair from the chain table key-value pair according to a comparison result;

[0024] inserting the target chain table key-value pair into an audit result table to obtain a comparison result.

[0025] Optionally, before the comparison of the comparison data in the business table with the chain table data to obtain a comparison result, the method further includes:

[0026] determining whether the database data extraction thread and the chain table data extraction thread are both executed completely;

[0027] When the database data extraction thread and the chain conversion table data extraction thread are both executed completely, a step of comparing the comparison data in the business table with the chain conversion table data to obtain a comparison result is executed.

[0028] Optionally, the repairing processing of the data on the blockchain according to the comparison result comprises:

[0029] An audit result table in the comparison result is obtained, and an order number to be repaired in the audit result table is extracted.

[0030] A to-be-chained data execution queue is generated according to the order number to be repaired, so that the blockchain adjusts a state or inserts data according to the to-be-chained data execution queue.

[0031] Optionally, after the to-be-chained data execution queue is generated according to the order number to be repaired, the method further comprises:

[0032] The number of chains of the to-be-chained data execution queue is obtained.

[0033] When the number of chains exceeds a preset number, a GRPC interface of a blockchain platform is called to execute a batch transaction smart contract, so that the blockchain adjusts the state or inserts the data according to the transaction smart contract.

[0034] In addition, to achieve the above-mentioned purpose, the application further provides a data auditing device based on a blockchain, which comprises:

[0035] A detection module is configured to obtain chain data from a previous period to a current time on a blockchain.

[0036] A conversion module is configured to convert the chain data to a chain conversion table of a database to obtain chain conversion table data.

[0037] A comparison module is configured to obtain comparison data in a business table of the database, compare the comparison data in the business table with the chain conversion table data, and obtain a comparison result.

[0038] A repairing module is configured to perform repairing processing of the data on the blockchain according to the comparison result, so as to ensure that the data on the blockchain is consistent with the data in the business table of the database.

[0039] In addition, to achieve the above-mentioned purpose, the application further provides a data auditing device based on a blockchain, which comprises a memory, a processor, and a data auditing program based on a blockchain stored in the memory and executable on the processor, wherein the data auditing program based on a blockchain is configured to implement the data auditing method based on a blockchain as described above.

[0040] In addition, to achieve the above object, the application further provides a storage medium, wherein the storage medium stores a blockchain-based data auditing program, and the blockchain-based data auditing program is executed by a processor to implement the blockchain-based data auditing method.

[0041] The blockchain-based data auditing method provided by the application obtains chain data from a blockchain from a previous period to a current time, stores the chain data in a chain conversion table of a database to obtain chain conversion table data, obtains comparison data in a business table of the database, compares the comparison data in the business table with the chain conversion table data to obtain a comparison result, and repairs the data on the blockchain according to the comparison result to ensure that the data on the blockchain is consistent with the data in the business table of the database. The chain data is sampled and stored in the chain conversion table, the data in the chain conversion table is compared with the data in the database to obtain inconsistent difference data on the blockchain and in the database, the data on the blockchain is repaired according to the difference data to ensure that the data on the blockchain is consistent with the data in the business table of the database, and the consistency of the data on the chain and the data off the chain is achieved. BRIEF DESCRIPTION OF DRAWINGS

[0042] Figure 1 It is a hardware running environment of the blockchain-based data auditing method device structure schematic diagram involved in the embodiment scheme of the application;

[0043] Figure 2 It is a flowchart of the first embodiment of the blockchain-based data auditing method of the application;

[0044] Figure 3 It is a blockchain-based data auditing system overall schematic diagram of the first embodiment of the blockchain-based data auditing method of the application;

[0045] Figure 4 It is a flowchart of the second embodiment of the blockchain-based data auditing method of the application;

[0046] Figure 5 It is an auditing logic schematic diagram of the first embodiment of the blockchain-based data auditing method of the application;

[0047] Figure 6 It is a flowchart of the third embodiment of the blockchain-based data auditing method of the application;

[0048] Figure 7 It is a functional module schematic diagram of the first embodiment of the blockchain-based data auditing device of the application.

[0049] The objectives, functional characteristics and advantages of the present application will be further described with reference to the embodiments and the accompanying drawings. DETAILED DESCRIPTION

[0050] It should be understood that the specific embodiments described herein merely exemplify the application and do not limit the application.

[0051] Reference Figure 1 , Figure 1 The device structure diagram of the hardware running environment involved in the embodiment of the present application is shown.

[0052] As Figure 1 shown, the device can include a processor 1001, such as a CPU, a communication bus 1002, a user interface 1003, a network interface 1004, and a memory 1005. The communication bus 1002 is used to realize the connection and communication between these components. The user interface 1003 can include a display screen (Display) and an input unit such as a key. The optional user interface 1003 can also include a standard wired interface and a wireless interface. The network interface 1004 can optionally include a standard wired interface and a wireless interface (such as a WI-FI interface). The memory 1005 can be a high-speed RAM memory or a stable memory (non-volatile memory) such as a magnetic disk memory. The memory 1005 can also be an independent storage device from the aforementioned processor 1001.

[0053] Those skilled in the art can understand that Figure 1 The device structure of the blockchain-based data auditing method shown in the figure does not constitute a limitation on the blockchain-based data auditing method device, and can include more or fewer components than the figure, or combine certain components, or different component arrangements.

[0054] As Figure 1 shown, the memory 1005 as a storage medium can include an operating system, a network communication module, a user interface module, and a blockchain-based data auditing method program.

[0055] In Figure 1 the blockchain-based data auditing method device shown, the network interface 1004 is mainly used to connect a server and communicate data with the server; the user interface 1003 is mainly used to connect a user terminal and communicate data with the terminal; the blockchain-based data auditing method device of the present application calls the blockchain-based data auditing method program stored in the memory 1005 through the processor 1001, and executes the blockchain-based data auditing method provided by the embodiment of the present application.

[0056] Based on the above hardware structure, the embodiment of the blockchain-based data auditing method of the present application is proposed.

[0057] Reference Figure 2 , Figure 2 This is a flowchart illustrating the first embodiment of the blockchain-based data auditing method of the present invention.

[0058] In the first embodiment, the blockchain-based data auditing method includes the following steps:

[0059] Step S10: Obtain on-chain data from the previous blockchain cycle to the current time.

[0060] It should be noted that the execution subject of this embodiment can be a blockchain-based data auditing device, which is equipped with a blockchain-based data auditing method program. It can also be other devices that can achieve the same or similar functions. This embodiment does not limit this. In this embodiment, an auditing server is used as an example for explanation. A blockchain-based data auditing application is provided on the auditing server, and data auditing can be performed according to the blockchain-based data auditing application.

[0061] In this embodiment, the application is a blockchain business processing system. This system includes interconnected business systems and external business systems. Data within the business systems is stored in a database. The external business systems interact with external blockchain nodes, which are managed through a blockchain network. Figure 3 The diagram shows the overall structure of a blockchain-based data auditing system. This system includes an on-chain data acquisition device, an auditing device, a reprocessing device, and a filter. The on-chain data acquisition device acquires data from the blockchain and stores it in a database. The auditing device audits the business table data in the database and the data transferred from the blockchain. The reprocessing device resubmits the audit discrepancies back to the blockchain. The filter cleans the data during the on-chain data acquisition process and sends the resubmitted data to the blockchain gateway, where blockchain nodes then transmit the resubmitted data into the blockchain network.

[0062] In the specific implementation, in order to ensure the timeliness of data, it is necessary to monitor the on-chain data in a timely manner. Therefore, on-chain data from the previous period to the current time is obtained through scheduled tasks to achieve on-chain data sampling. Block node data on the blockchain within the current time period is obtained by calling the GRPC interface of the blockchain platform. For example, the latest node number is obtained by calling get_info() on the EOS blockchain platform, and block node data is obtained by getting_block().

[0063] Step S20: Transfer the on-chain data to the linked list in the database to obtain the linked list data.

[0064] It should be noted that, continuing as Figure 3 As shown, the database includes a business table, a chain transfer table, and a result table. The business table stores data related to the business system, the chain transfer table stores data transferred by the on-chain data acquisition device, and the result table stores the comparison results between the data in the business table and the data in the chain transfer table. The comparison results are then sent to the reprocessing device so that the reprocessing device can repair the data on the blockchain based on the comparison results, and then submit the data to the blockchain gateway for further processing.

[0065] To obtain more accurate on-chain data, the on-chain data is compared with the data in the filter. Based on the comparison result, the latest on-chain data state is obtained and transferred to the chain transfer table in the database. The chain transfer table data is then obtained by calling the blockchain RPC interface to query the latest on-chain data node number. This process iterates from the previous block number to the current latest number, calling the RPC interface to retrieve node data. The filter is then queried based on the node's order number. If the node already exists in the filter, an update statement is generated; otherwise, an insert statement is generated, and the node's order number is written into the filter. The update and insert statements are executed sequentially within a single transaction. The process involves submitting the data, then saving the current node as the node number of the previous round, and saving the current time as the audit time of the previous round. Specifically, it checks whether a value with the order number field of the current block node as the key already exists in the filter cache using `redis.get(key)`. If it already exists, the data of the current block node is converted into a database table update statement. If it does not exist, a database table insert statement is generated, and the order number and order data of the block node are inserted into the filter cache. After the block nodes within the current time period are traversed, the database transaction script is submitted in batches. This allows for data management and status query through node numbers, improving the effectiveness of data processing.

[0066] Step S30: Obtain the comparison data from the business table in the database, compare the comparison data from the business table with the data in the linked table, and obtain the comparison result.

[0067] In the specific implementation, when performing data comparison, each row of data in the business table of the database is obtained to form a hash pair. The key is calculated by adding the order number and the order content, and the value is calculated by adding the order number and the order content. Correspondingly, the data in the chain transfer table is also obtained in the same way to obtain key-value pairs. The two key-value pairs are compared to obtain the comparison result. The comparison result includes data that exists in the business database but not in the blockchain, as well as data that exists in the blockchain but not in the database.

[0068] Step S40: Repair the data on the blockchain according to the comparison results to ensure that the data on the blockchain is consistent with the data in the business table of the database.

[0069] Understandably, the repair process includes either a rollback operation or an insertion operation. A rollback operation involves executing a transaction using the previous transaction status data of the order number and inserting the data into the queue of data to be uploaded to the blockchain. An insertion operation involves inserting missing data into the queue of data to be uploaded to the blockchain, thus processing the data on the blockchain. For data that exists in the business database but not on the blockchain, an insertion operation is used to insert the missing data into the queue of data to be uploaded to the blockchain. For data that exists on the blockchain but not in the database, a rollback operation is performed, executing a transaction using the previous transaction status data of the order number corresponding to the redundant data and inserting the data into the queue of data to be uploaded to the blockchain, thereby changing the on-chain state of the redundant data and ensuring consistency between the data on the blockchain and the data in the business tables of the database.

[0070] In this embodiment, on-chain data from the previous period to the current time is obtained; the on-chain data is transferred to a chain transfer table in the database to obtain chain transfer table data; comparison data from the business table in the database is obtained, and the comparison data in the business table is compared with the chain transfer table data to obtain a comparison result; the data on the blockchain is repaired based on the comparison result to ensure that the data on the blockchain and the data in the business table of the database are consistent. By sampling the on-chain data and transferring it to the chain transfer table, the data in the chain transfer table is compared with the data in the database to obtain the discrepancy data between the blockchain and the database. The data on the blockchain is repaired based on the discrepancy data to ensure that the data on the blockchain and the data in the business table of the database are consistent, thereby achieving consistency between on-chain and off-chain data.

[0071] In one embodiment, such as Figure 4 As shown, based on the first embodiment, a second embodiment of the blockchain-based data auditing method of the present invention is proposed. Step S20 includes:

[0072] Step S201: Obtain the node data of the on-chain data, and determine the order number value based on the node data.

[0073] In a specific implementation, a preset extraction keyword can be obtained. When obtaining the node data of the on-chain data, the preset extraction keyword is matched with the node data of the on-chain data, and the order number value in the node data is obtained based on the matching result.

[0074] Step S202: Generate key-value pairs based on the order number value.

[0075] In this embodiment, the order number value is used as the key, and the content corresponding to the order number value is used as the value to generate a key-value pair. For example, the order number field of the current block node is the key and the value is redis.get(key), which facilitates comparison with the data in the preset filter.

[0076] Step S203: Compare the key-value pair with the key-value pair in the preset filter cache, wherein the data in the preset filter cache is consistent with the data in the database.

[0077] It's important to note that the preset filter is a Redis cache cluster used by the on-chain data retrieval device to transfer data to the database table. After each on-chain data retrieval, the system first checks if the corresponding key / value pair exists in the preset filter cache. If it does, it means the current on-chain table already contains data for the corresponding order number, and the existing order status and other data in the current table need to be updated to reflect the latest order data retrieved from the on-chain database, generating an update statement. If the filter does not contain the corresponding key / value pair, it means the database does not contain the corresponding order number data, generating an insert statement, and simultaneously uploading the corresponding order number and order data as a key and value to Redis.

[0078] Step S204: Determine the database statement based on the comparison results.

[0079] Understandably, when transferring the on-chain data obtained by the on-chain data acquisition device to the database, it is necessary to process it with corresponding database statements. That is, the key-value pairs of the on-chain data are compared with the key-value pairs in the preset filter cache. If the key-value pairs of the on-chain data already exist in the preset filter cache, the data of the current block node corresponding to the key-value pair is converted into a database table update statement. If it does not exist, a database table insert statement is generated, and the order number and order data of the block node are inserted into the filter cache to achieve timely updates of the filter content.

[0080] Step S205: Transfer the on-chain data to the database according to the database statement to obtain the linked list data.

[0081] In this embodiment, when transferring on-chain data to the database's transfer table for comparison, the large amount of on-chain data can easily consume a lot of computing power during subsequent data comparisons. Therefore, before transferring on-chain data to the database's transfer table for comparison, the on-chain data is filtered to ensure data validity and improve data processing efficiency.

[0082] In one embodiment, step S30 includes:

[0083] A multi-threaded startup instruction is invoked, and a database data extraction thread and a linked table data extraction thread are obtained according to the multi-threaded startup instruction. The database data extraction thread extracts comparison data from the business table, and after a preset time interval, the linked table data extraction thread extracts linked table data from the linked table. The comparison data in the business table is compared with the linked table data to obtain the comparison result.

[0084] In this embodiment, multi-threaded comparison calculation is adopted, which has high scalability and low resource consumption. For example, through multi-threaded concurrency, one thread starts first and reads the value in the business table and stores it in ConcurrentHashMap. Another thread starts late and reads the chain transfer table data transferred from the blockchain to the database. The hash container key / value is constructed with the order number + the hash value of the order content and the original value. The two hash containers are compared, the same value is eliminated, and the final difference result value between the database and the blockchain is obtained.

[0085] In the specific implementation, the comparison data in the business table is compared with the linked table data to obtain the comparison result. Specifically, the following steps are taken: the order number and order content are extracted from the comparison data, and database key-value pairs are generated based on the order number and order content; the order number and order content are extracted from the linked table data, and linked table key-value pairs are generated based on the order number and order content; the database key-value pairs are compared with the linked table key-value pairs, and a target linked table key-value pair that does not contain the database key-value pair is selected from the linked table key-value pairs based on the comparison result; the target linked table key-value pair is inserted into the audit result table to obtain the comparison result.

[0086] In this embodiment, continue as follows Figure 3 As shown, the audit result table is a result table used in the database to store the comparison results. By using the comparison results in the audit result table, the data on the blockchain can be repaired.

[0087] Another embodiment is provided for detailed explanation, and the audit device executes its logic in detail, such as... Figure 5The audit logic diagram shown illustrates that one thread is responsible for extracting data from the business table `table_db` in database A. Each row of data is constructed into a hash pair, with the key calculated by adding the order number and order content. The value in `ConcurrentHashMapA` is calculated using the order number and order content. Thread B starts with a delay and performs the same calculation, reading the linked list table `table_bcn`. Simultaneously, the data extracted by thread B is first compared with the data in `HashMap_A`. If it exists in container A, it means that this record is the same in both databases (`ConcurrentHashMapA.get(key_B) = ConcurrentHashMapB.get(key_B)`), then this record can be deleted from A's Map (`ConcurrentHashMapA.remove(key_B)`), and B can directly discard this record without placing it in `HashMap_B`. If it does not exist in A, then container A is not processed, and B puts it into `HashMap_B` (`ConcurrentHashMapB.put(key_B, value)`).

[0088] In one embodiment, before comparing the comparison data in the business table with the data in the linked table to obtain the comparison result, the method further includes:

[0089] Determine whether both the database data extraction thread and the linked table data extraction thread have completed execution; when both the database data extraction thread and the linked table data extraction thread have completed execution, perform the step of comparing the comparison data in the business table with the linked table data to obtain the comparison result.

[0090] Continue as Figure 5 As shown, after A finishes extracting data from the table, B may not have finished yet. Therefore, it's necessary to wait for both threads to complete their processing before comparing the two Maps. Identical data is removed, and different data is retained. After the comparison, Map A contains data that is not in Map B—data that exists in the business database but not on the blockchain. This ensures that data comparison is performed only after all threads have completed their execution, improving the accuracy of the data comparison.

[0091] In this embodiment, key-value pairs are generated using order number and order content. These database key-value pairs are compared with the linked list key-value pairs. Based on the comparison result, a target linked list key-value pair that does not contain the database key-value pair is selected from the linked list key-value pairs. The target linked list key-value pair is then inserted into the audit result table to obtain the comparison result, thereby achieving the comparison between the data in the database and the data in the blockchain.

[0092] In one embodiment, such as Figure 6As shown, a third embodiment of the blockchain-based data auditing method of the present invention is proposed based on the first or second embodiment. Taking the first embodiment as an example, step S40 includes:

[0093] Step S401: Obtain the audit result table from the comparison results, and extract the order number to be repaired from the audit result table.

[0094] In this embodiment, the audit result table contains the comparison results between the linked table data and the data in the business table of the database. The comparison results are in key-value pairs. The key is calculated by adding the order number and the order content to calculate the hash value. The value of ConcurrentHashMapA is the order number and the order content. Therefore, by parsing the audit result table, the data information of the mismatch between the linked table data and the data in the business table of the database can be obtained, including the order number to be repaired and the order content.

[0095] Step S402: Generate a data execution queue to be uploaded to the blockchain based on the order number to be repaired, so that the blockchain can perform state adjustment or data insertion based on the data execution queue to be uploaded to the blockchain.

[0096] In the specific implementation, if there is too much data on the chain, a reversal operation is initiated. Since the blockchain does not support the deletion of on-chain data, the transaction operation is performed using the previous transaction status data of the order number, and the data is inserted into the queue of data to be added to the chain. This changes the data status in the blockchain according to the queue of data to be added to the chain, so as to ensure that the data on the blockchain is consistent with the data in the business table of the database. If there is too little data on the chain, the missing data is inserted into the queue of data to be added to the chain, so as to ensure that the data on the blockchain is consistent with the data in the business table of the database, thereby realizing the synchronization of data in the database and data in the blockchain.

[0097] In one embodiment, after step S402, the method further includes:

[0098] Obtain the number of data to be uploaded to the blockchain in the execution queue; when the number of data to be uploaded to the blockchain exceeds a preset number, call the GRPC interface of the blockchain platform to execute a batch transaction smart contract, so that the blockchain adjusts the state of the data to be uploaded to the blockchain or inserts data according to the transaction smart contract.

[0099] In this embodiment, the preset quantity can be 100 data execution queues to be uploaded to the blockchain, or it can be other parameters. This embodiment does not limit this; taking 100 as an example, if the number of data execution queues to be uploaded to the blockchain needs to be adjusted to 1000, it will exceed the preset quantity. In this case, if the queues are processed one by one, the processing time will be long and consume a lot of system performance. Therefore, a batch processing method can be used to process the data execution queues to be uploaded to the blockchain, that is, calling the GRPC interface of the blockchain platform to execute batch transaction smart contracts, so that the blockchain can adjust the state of the data execution queues to be uploaded to the blockchain or insert data according to the transaction smart contracts. The specific calling method is as follows:

[0100] For(){Json +=;}

[0101] push_transactions(json_data);

[0102] This embodiment also provides an overall operation flow. First, a scheduled task initiates a call to the on-chain data acquisition device to periodically acquire on-chain data from the previous period to the current time. For each block node data acquired, it checks whether the corresponding key-value pair already exists in the filter device. Based on the existence of the key, a corresponding SQL statement is generated and submitted in batches. After execution, the audit device API interface is called to retrieve data from the business table and the chain transfer table for audit comparison. For discrepancies in the comparison results, alarm data is generated. After manual confirmation, a reprocessing operation is performed, calling the blockchain platform's GRPC interface to execute a batch transaction smart contract. This either adds missing data to the chain or reverses excess data, thereby achieving data repair on the blockchain.

[0103] In this embodiment, the on-chain data is repaired based on the audit comparison results through a reprocessing mechanism. For the extra data on the chain, the previous state data is re-added to the chain to overwrite the current state, realizing the on-chain reversal operation, thereby realizing the state adjustment of blockchain data that cannot be deleted.

[0104] The present invention further provides a data auditing device based on blockchain.

[0105] Reference Figure 7 , Figure 7 This is a schematic diagram of the functional modules of the first embodiment of the blockchain-based data auditing device of the present invention.

[0106] In the first embodiment of the blockchain-based data auditing device of the present invention, the blockchain-based data auditing device includes:

[0107] The detection module 10 is used to obtain on-chain data from the previous blockchain cycle to the current time.

[0108] In this embodiment, the application is a blockchain business processing system. This system includes interconnected business systems and external business systems. Data within the business systems is stored in a database. The external business systems interact with external blockchain nodes, which are managed through a blockchain network. Figure 3 The diagram shows the overall structure of a blockchain-based data auditing system. This system includes an on-chain data acquisition device, an auditing device, a reprocessing device, and a filter. The on-chain data acquisition device acquires data from the blockchain and stores it in a database. The auditing device audits the business table data in the database and the data transferred from the blockchain. The reprocessing device resubmits the audit discrepancies back to the blockchain. The filter cleans the data during the on-chain data acquisition process and sends the resubmitted data to the blockchain gateway, where blockchain nodes then transmit the resubmitted data into the blockchain network.

[0109] In the specific implementation, in order to ensure the timeliness of data, it is necessary to monitor the on-chain data in a timely manner. Therefore, on-chain data from the previous period to the current time is obtained through scheduled tasks to achieve on-chain data sampling. Block node data on the blockchain within the current time period is obtained by calling the GRPC interface of the blockchain platform. For example, the latest node number is obtained by calling get_info() on the EOS blockchain platform, and block node data is obtained by getting_block().

[0110] The transfer module 20 is used to transfer the on-chain data to the linked transfer table of the database to obtain the linked transfer table data.

[0111] It should be noted that, continuing as Figure 3 As shown, the database includes a business table, a chain transfer table, and a result table. The business table stores data related to the business system, the chain transfer table stores data transferred by the on-chain data acquisition device, and the result table stores the comparison results between the data in the business table and the data in the chain transfer table. The comparison results are then sent to the reprocessing device so that the reprocessing device can repair the data on the blockchain based on the comparison results, and then submit the data to the blockchain gateway for further processing.

[0112] To obtain more accurate on-chain data, the on-chain data is compared with the data in the filter. Based on the comparison result, the latest on-chain data state is obtained and transferred to the chain transfer table in the database. The chain transfer table data is then obtained by calling the blockchain RPC interface to query the latest on-chain data node number. This process iterates from the previous block number to the current latest number, calling the RPC interface to retrieve node data. The filter is then queried based on the node's order number. If the node already exists in the filter, an update statement is generated; otherwise, an insert statement is generated, and the node's order number is written into the filter. The update and insert statements are executed sequentially within a single transaction. The process involves submitting the data, then saving the current node as the node number of the previous round, and saving the current time as the audit time of the previous round. Specifically, it checks whether a value with the order number field of the current block node as the key already exists in the filter cache using `redis.get(key)`. If it already exists, the data of the current block node is converted into a database table update statement. If it does not exist, a database table insert statement is generated, and the order number and order data of the block node are inserted into the filter cache. After the block nodes within the current time period are traversed, the database transaction script is submitted in batches. This allows for data management and status query through node numbers, improving the effectiveness of data processing.

[0113] The comparison module 30 is used to obtain comparison data from the business table in the database, compare the comparison data in the business table with the data in the linked table, and obtain the comparison result.

[0114] In the specific implementation, when performing data comparison, each row of data in the business table of the database is obtained to form a hash pair. The key is calculated by adding the order number and the order content, and the value is calculated by adding the order number and the order content. Correspondingly, the data in the chain transfer table is also obtained in the same way to obtain key-value pairs. The two key-value pairs are compared to obtain the comparison result. The comparison result includes data that exists in the business database but not in the blockchain, as well as data that exists in the blockchain but not in the database.

[0115] Repair module 40 is used to repair the data on the blockchain based on the comparison results, so as to ensure that the data on the blockchain is consistent with the data in the business table of the database.

[0116] In this embodiment, the repair process includes a reversal operation or an insertion operation. The reversal operation involves executing a transaction operation using the previous transaction status data of the order number and inserting the data into the queue of data to be uploaded to the blockchain. The insertion operation involves inserting the missing data into the queue of data to be uploaded to the blockchain, thereby realizing data processing on the blockchain. For data that exists in the business database but not on the blockchain, an insertion operation is used to insert the missing data into the queue of data to be uploaded to the blockchain. For data that exists in the blockchain but not in the database, a reversal operation is performed, executing a transaction operation using the previous transaction status data of the order number corresponding to the redundant data and inserting the data into the queue of data to be uploaded to the blockchain, thereby changing the on-chain state of the redundant data and ensuring that the data on the blockchain and the data in the business table of the database are consistent.

[0117] In this embodiment, on-chain data from the previous period to the current time is obtained; the on-chain data is transferred to a chain transfer table in the database to obtain chain transfer table data; comparison data from the business table in the database is obtained, and the comparison data in the business table is compared with the chain transfer table data to obtain a comparison result; the data on the blockchain is repaired based on the comparison result to ensure that the data on the blockchain and the data in the business table of the database are consistent. By sampling the on-chain data and transferring it to the chain transfer table, the data in the chain transfer table is compared with the data in the database to obtain the discrepancy data between the blockchain and the database. The data on the blockchain is repaired based on the discrepancy data to ensure that the data on the blockchain and the data in the business table of the database are consistent, thereby achieving consistency between on-chain and off-chain data.

[0118] In one embodiment, the transfer module 20 is further configured to acquire node data of the on-chain data and determine the order number value based on the node data;

[0119] Generate key-value pairs based on the order number value;

[0120] The key-value pairs are compared with key-value pairs in a preset filter cache, wherein the data in the preset filter cache is consistent with the data in the database;

[0121] Determine the database statement based on the comparison results;

[0122] The on-chain data is transferred to the database according to the database statement to obtain the linked table data.

[0123] In one embodiment, the comparison module 30 is further configured to invoke a multi-threaded startup instruction to obtain a database data extraction thread and a linked list data extraction thread based on the multi-threaded startup instruction.

[0124] The database data extraction thread extracts comparison data from the business table, and after a preset time interval, the linked table data extraction thread extracts linked table data from the linked table.

[0125] The comparison data in the business table is compared with the data in the linked table to obtain the comparison result.

[0126] In one embodiment, the comparison module 30 is further configured to extract the order number and order content from the comparison data, and generate database key-value pairs based on the order number and order content from the comparison data;

[0127] Extract the order number and order content from the linked list data, and generate linked list key-value pairs based on the order number and order content.

[0128] The database key-value pairs are compared with the linked list key-value pairs, and a target linked list key-value pair that does not contain the database key-value pairs is selected from the linked list key-value pairs based on the comparison result.

[0129] Insert the target linked list key-value pairs into the audit result table to obtain the comparison results.

[0130] In one embodiment, the comparison module 30 is further configured to determine whether both the database data extraction thread and the linked list data extraction thread have been completed.

[0131] In one embodiment, the repair module 40 is further configured to obtain the audit result table in the comparison result and extract the order number to be repaired from the audit result table;

[0132] A data execution queue to be uploaded to the blockchain is generated based on the order number to be repaired, so that the blockchain can perform state adjustment or data insertion based on the data execution queue to be uploaded to the blockchain.

[0133] In one embodiment, the repair module 40 is further configured to obtain the number of data to be added to the chain in the execution queue;

[0134] When the number of data uploaded to the blockchain exceeds a preset number, the GRPC interface of the blockchain platform is invoked to execute a batch transaction smart contract, so that the blockchain performs state adjustment or data insertion on the queue of data to be uploaded to the blockchain according to the transaction smart contract.

[0135] Furthermore, to achieve the above objectives, the present invention also proposes a blockchain-based data auditing device, which includes: a memory, a processor, and a blockchain-based data auditing program stored in the memory and executable on the processor. The blockchain-based data auditing program is configured to implement the blockchain-based data auditing method described above.

[0136] Furthermore, this embodiment of the invention also proposes a storage medium storing a blockchain-based data audit program, which, when executed by a processor, implements the blockchain-based data audit method described above.

[0137] Since this storage medium adopts all the technical solutions of all the above embodiments, it has at least all the beneficial effects brought about by the technical solutions of the above embodiments, which will not be repeated here.

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

[0139] The sequence numbers of the above embodiments of the present invention are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.

[0140] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a computer-readable storage medium (such as ROM / RAM, magnetic disk, optical disk) as described above, and includes several instructions to cause a smart terminal (which may be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in the various embodiments of the present invention.

[0141] The above are merely preferred embodiments of the present invention and do not limit the scope of the patent. Any equivalent structural or procedural transformations made based on the description and drawings of the present invention, or direct or indirect applications in other related technical fields, are similarly included within the scope of patent protection of the present invention.

Claims

1. A blockchain-based data auditing method, characterized in that, The blockchain-based data auditing method comprises: acquiring on-chain data of a period to the current time on a blockchain; acquiring node data of the on-chain data and determining an order number value according to the node data; generating a key-value pair according to the order number value; comparing the key-value pair with a key-value pair in a preset filter cache, wherein data in the preset filter cache is consistent with data in a database; determining a database statement according to a comparison result; storing the on-chain data to the database according to the database statement to obtain chain conversion table data; acquiring comparison data in a business table of the database, comparing the comparison data in the business table with the chain conversion table data, and obtaining a comparison result; performing repair processing on data on the blockchain according to the comparison result to ensure that the data on the blockchain is consistent with the data in the business table of the database.

2. The blockchain-based data auditing method of claim 1, wherein, The acquiring of the comparison data in the business table of the database, the comparison of the comparison data in the business table with the chain conversion table data, and the obtaining of the comparison result comprise: calling a multi-thread starting instruction to obtain a database data extraction thread and a chain conversion table data extraction thread according to the multi-thread starting instruction; extracting comparison data from the business table through the database data extraction thread and extracting chain conversion table data from the chain conversion table through the chain conversion table data extraction thread after a preset time interval; comparing the comparison data in the business table with the chain conversion table data to obtain a comparison result.

3. The blockchain-based data auditing method of claim 2, wherein, The comparison of the comparison data in the business table with the chain conversion table data to obtain a comparison result comprises: extracting an order number and order content in the comparison data to generate a database key-value pair according to the order number and order content in the comparison data; extracting an order number and order content in the chain conversion table data to generate a chain conversion table key-value pair according to the order number and order content in the chain conversion table data; comparing the database key-value pair with the chain conversion table key-value pair and selecting a target chain conversion table key-value pair that does not contain the database key-value pair from the chain conversion table key-value pair according to a comparison result; inserting the target chain conversion table key-value pair into an auditing result table to obtain a comparison result.

4. The blockchain-based data auditing method of claim 2, wherein, Before the comparison of the comparison data in the business table with the chain conversion table data to obtain a comparison result, the method further comprises: determining whether the database data extraction thread and the chain conversion table data extraction thread are both executed; when the database data extraction thread and the chain conversion table data extraction thread are both executed, performing the comparison of the comparison data in the business table with the chain conversion table data to obtain a comparison result.

5. The blockchain-based data auditing method of any one of claims 1 to 4, wherein, The repair processing on the data on the blockchain according to the comparison result comprises: acquiring an auditing result table in the comparison result and extracting a to-be-repaired order number in the auditing result table; generating a to-be-chained data execution queue according to the to-be-repaired order number to enable the blockchain to perform state adjustment or data insertion according to the to-be-chained data execution queue.

6. The blockchain-based data auditing method of claim 5, wherein, After the generation of the to-be-chained data execution queue according to the to-be-repaired order number, the method further comprises: Obtaining a number of on-chain data execution queues; When the number of on-chain data execution queues exceeds a preset number, calling a GRPC interface of a blockchain platform to execute a batch transaction smart contract, so that the blockchain adjusts the state or inserts data into the on-chain data execution queue according to the transaction smart contract. 7.A blockchain-based data auditing apparatus, characterized in that, The blockchain-based data auditing device comprises: A detection module is configured to obtain on-chain data from a previous period to a current time on a blockchain; A storage module is configured to obtain node data of the on-chain data and determine an order number value according to the node data; A key-value pair is generated according to the order number value; The key-value pair is compared with key-value pairs in a preset filter cache, wherein data in the preset filter cache is consistent with data in a database; A database statement is determined according to a comparison result; The on-chain data is stored into the database according to the database statement, and chain table data is obtained; A comparison module is configured to obtain comparison data in a business table of the database, compare the comparison data in the business table with the chain table data, and obtain a comparison result; A repair module is configured to repair data on the blockchain according to the comparison result, so as to ensure that the data on the blockchain is consistent with the data in the business table of the database. 8.A blockchain-based data auditing device, characterized in that, The blockchain-based data auditing device comprises a memory, a processor, and a blockchain-based data auditing program stored in the memory and executable on the processor, and the blockchain-based data auditing program is configured to implement the blockchain-based data auditing method in any one of claims 1 to 6.

9. A storage medium, characterized by The storage medium stores a blockchain-based data auditing program, and the blockchain-based data auditing program is executed by the processor to implement the blockchain-based data auditing method in any one of claims 1 to 6.

Citation Information

Patent Citations

  • Data verification method based on blockchain

    CN112486944A